mysql leftjoin最新记录,mysql left join选择左右表中的所有记录,即使rigth表中没有记录也是如此...

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.

解决方案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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值