数据库几种连接方式的(左右union all)

A表

id  name

1  bai

2  zhang

3  li  

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; //不删除重复项

原文地址:https://www.cnblogs.com/Wen-yu-jing/p/4316137.html