码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-03-05 18:35:45      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!