Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 tables in MYSQL like:
rec_application=>AppId(PK),AppNum
rec_shortlistedCandidates=>ShortListId(PK),AppId(FK),TotalScore
rec_shortListedScore=>AppId(FK),TestId,Score,Comment


I want to list the Shortlisted candidates with there AppNum,Score and Comment for the selected TestId[on a dropdown change].The TestId can or can't be there in the 'rec_shortListedScore',if not present then Score=0 and Comment=null.

i tried :
SELECT S.AppId,SL.Score,SL.Comments,A.AppNum

FROM rec_shortlistedcandidates S

INNER JOIN rec_application A ON A.AppId=S.AppId
left JOIN rec_shortlistscore SL ON SL.AppId=S.AppId;

but this displays only when the 'rec_shortlistscore' have data in it.
Posted

1 solution

A left outer join will do this. It returns all records from the right table, with nulls if the left table has no match

SQL Wizardry Part One - Joins[^] is my first SQL article, and it explains it.
 
Share this answer
 
v2
Comments
fiashieen 23-Jan-14 3:29am    
Thanks for you reply...but its not working, when i am checking with the condition as
"where TestId='1'".Actually i want the output on the basis of the TestId i am selecting.once the table rec_shortListedScore contains data this is working properly else its not...:(
Christian Graus 23-Jan-14 3:36am    
If you're checking a condition that is in the first table, then you need to do where (TestId = 1 or TestId is null) because when it's null ( from the left join ), it does not equal 1.
fiashieen 23-Jan-14 4:04am    
oh...may be problem is that, the TestId which i'm using for the condition is only in the table which is used for Left join.so i think i must use a "union" to solve the issue is it??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900