sql语句查询
表A:
id username
1 tt
2 yy
3 ee
表B:
id address A_id
1 aaa 1
怎么利用sql语句查询 得到 :
id username address
1 tt aaa
2 yy
3 ee
新手,网上都不知道怎么查资料,纠结半天了。。。。。。。。
大家也可以介绍下学习数据库的经验。。
[解决办法]
用left join
select a.id,a.username,b.address from a left join b on a.id = b.A_id
[解决办法]
select a.id,a.username,b.address from t_user a left join t_address b on a.id = b.A_id
[解决办法]
原来是把不符合记录的也显示。那就用左外连接了
[解决办法]
select a.id,a.username,b.address from a left join b on a.id = b.A_id
[解决办法]
select a.id,a.username,b.address from A a with (nolock)left join B b with (nolock) on a.id=b.A_id
[解决办法]
select a.id,a.username,b.address from a , b where a.id = b.A_id(+);
[解决办法]
通用写法
select a.id,a.username,b.address from a left join b on a.id = b.A_id;
oracle 可以用
select a.id,a.username,b.address from a , b where a.id = b.A_id(+);
[解决办法]
select a.id,a.username,b.address from a left join b on a.id = b.A_id