1. 程式人生 > >left join 左邊有資料,右邊無資料,查詢結果出現inner join的情況(and 和 where 的區別)

left join 左邊有資料,右邊無資料,查詢結果出現inner join的情況(and 和 where 的區別)

A表
id   aname 
1    張三
2    李四

B表
id    score  aid     bname  year
1      90      1     語文    2015
2      92      1     數學    2016


select aname,bname,score from A left join B on A.id=B.aid where year='2015'


查詢結果

張三 語文 90



select aname,bname,score from A left join B on A.id=B.aid and year='2015'

查詢結果

張三 語文 90
李四 null null

select aname,bname,score from A left join B on A.id=B.aid where year=’2015’

select aname,bname,score from A left join B on A.id=B.aid and year=’2015’