舟山有什么好玩的:有null值的两表关联sql语句

来源:百度文库 编辑:高校问答 时间:2024/05/14 17:27:55
a表:
id userid
01 111
02 222
03 null
b表:
userid name
111 jacky
222 tom

怎样才能查询到一下结果:
id userid name
01 111 jacky
02 222 tom
03 null null

请不惜赐教,谢谢!

使用左外联接
select a.id,a.userid,b.name from a,b where a.userid*=b.userid
注意比上边多个“*”
select a.id,a.userid,b.name from a outer left join b on a.userid=b.userid ,这个应该可以在mssql下运行。

select a.id,a.userid,b.name from a,b where a.userid=b.userid

Select A.ID,A.userID,B.name From A Left Join B ON A.userID=B.userID