数据库几种连接方式的(左右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; //刪除重復(fù)相
select id ?name ?from A a union all ?select b.a_id id,score name B b; //不刪除重復(fù)項
?
轉(zhuǎn)載于:https://www.cnblogs.com/Wen-yu-jing/p/4316137.html
總結(jié)
以上是生活随笔為你收集整理的数据库几种连接方式的(左右union all)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据产品-规则型和挖掘型标签构建案例
- 下一篇: linux cmake编译源码,linu