码迷,mamicode.com
首页 > 其他好文 > 详细

left ,right ,cross ,full/left outer join/区别 详解

时间:2015-10-30 00:52:27      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

--创建测试表ww
if OBJECT_ID(‘qq‘) is not null drop table qq
create table qq([序号] varchar(5),[内容1] varchar(10),[内容2] varchar(15))
insert into qq([序号],[内容1],[内容2])
select ‘dd‘,‘zoumin‘,‘yuzulin‘
union all
select ‘cc‘,‘zm‘,‘yz‘
union all
select ‘AA‘,‘z1‘,‘yz1‘
union all
select ‘BB‘,‘zm2‘,‘yz2‘
select * from qq
drop table qq

--创建测试表 ww

if OBJECT_ID(‘ww‘) is not null drop table ww
create table ww([序号] varchar(5),[内容1] varchar(10),[内容2] varchar(15))
insert into ww([序号],[内容1],[内容2])
select ‘ee‘,‘ee‘,‘rr‘
union all
select ‘ff‘,‘tt‘,‘yy‘
union all
select ‘AA‘,‘tt1‘,‘yy1‘
union all
select ‘BB‘,‘tt1‘,‘yy1‘
select * from ww
drop table ww


--内连接(inner可省)
select * from qq inner join ww on qq.序号=ww.序号
--On 条件可变得内连接
select * from qq inner join ww on qq.序号!=ww.序号
--交叉连接(加where 条件后=inner join)
select * from qq cross join ww where qq.序号=ww.序号

--交叉连接(逗号形式的)
select * from qq , ww where qq.序号=ww.序号
--左连接
select * from qq left join ww on qq.序号=ww.序号
--做外连接=左连接
select * from qq left outer join ww on qq.序号=ww.序号
--右连接
select * from qq right join ww on qq.序号=ww.序号
--全连接=left+right
select * from qq full join ww on qq.序号=ww.序号

left ,right ,cross ,full/left outer join/区别 详解

标签:

原文地址:http://www.cnblogs.com/zoumin123/p/4922180.html

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