关于sql语句联合查询时碰到空值时的问题
table1:people
id name deptid
1 a 12
2 b 13
3 c
table2:department
id name
12 x1
13 x2
14 x3
我用这样的sql语句(select a.id,a.name,b.deptname from people a,department b where a.deptid = b.id),但是只能查出
id name deptname
1 a x1
2 b x2
如何使查询出的下面结果,即当people表中deptid为空时,能查询出下面结果,要在一句sql语句中实现的:
id name deptname
1 a x1
2 b x2
3 c
------解决方案--------------------select a.id,a.name,b.deptname from people a
left join department b on a.deptid = b.id