leftjoin带条件查询没有返回右表为NULL的

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

参考
https://blog.csdn.net/chenjianandiyi/article/details/52402011

https://blog.csdn.net/php_girl/article/details/77478429?utm_source=blogxgwz0

猜你喜欢

转载自blog.csdn.net/u012848709/article/details/83150804