A表io
id nameselect
1 bainio
2 zhangco
3 li join
B表
a_id score
1 80
2 70
1 30
左鏈接:
select A.* ,B.* from A a left outer join B b on a.id = b.a_id;
result:
id name a_id score
1 bai 1 80
1 bai 1 30
2 zhang 2 70
3 li null null
select A.* ,B.* from B b right outer join A a on a.id = b.a_id;
result:
id name a_id score
1 bai 1 80
1 bai 1 30
2 zhang 2 70
3 li null null
select id name from A a union select b.a_id id,score name B b; //刪除重複相
select id name from A a union all select b.a_id id,score name B b; //不刪除重複項