22,207
社区成员
发帖
与我相关
我的任务
分享
on 后面是连接条件(两个相等时).
full join =左连接+右连接
lz看看join的用法...
select * from table1 full join table2 on table1.name1<>table1.name1
-- =========================================
-- -----------t_mac 小编-------------
---希望有天成为大虾----
-- =========================================
IF OBJECT_ID('tb1') IS NOT NULL
DROP TABLE tb1
GO
CREATE TABLE tb1(name1 varchar(10),phone int)
go
insert into tb1
select '1',1
go
IF OBJECT_ID('tb2') IS NOT NULL
DROP TABLE tb2
GO
CREATE TABLE tb2(name2 varchar(10),address varchar(10))
go
insert into tb2
select 'sd','sdfad'
go
select * from tb1 full join tb2 on name1=name2
/*------------
name1 phone name2 address
---------- ----------- ---------- ----------
1 1 NULL NULL
NULL NULL sd sdfad
(2 行受影响)
-------*/
select *
from table1,table2