以后你还会用到left join,right join,cross join 等等.
革命尚未成功,同志仍需努力-----+++
你开始又不说清楚,人家purana版主又怎么知道.
purana上边的方法已经实现了你预期的效果,LZ不要钻牛角尖.
实现你所说的方法也不难嘛:
create database abcde
go
use abcde
go
create table a(
id int primary key,
name char(8),
sex char(2)
)
go
create table c(
id int primary key,
name char(8),
sex char(2)
)
go
create table d(
id int primary key,
name char(8),
sex char(2)
)
go
create table e(
id int primary key,
name char(8),
sex char(2)
)
go
insert into a
values(101,'张三','男')
go
insert into a
values(102,'李四','女')
go
insert into a
values(103,'王五','男')
go
insert into c
values(101,'张三','男')
go
insert into c
values(102,'李四','女')
go
insert into c
values(103,'王五','男')
go
insert into c
values(104,'陈六','女') --多出的
go
insert into d
values(101,'张三','男')
go
insert into d
values(102,'李四','女')
go
insert into d
values(103,'王五','男')
go
insert into d
values(104,'陈六','女') --多出的
go
insert into e
values(101,'张三','男')
go
insert into e
values(102,'李四','女')
go
insert into e
values(103,'王五','男')
go
insert into e
values(104,'陈六','女') --多出的
go
use abcde
go
select b.* from
(select c.* from c,d,e
where (c.id=d.id) and (c.id=e.id) and (d.id=e.id)
) as b
where b.id not in(select id from a)
go
查询结果:
id name sex
--- ---- ----
104 陈六 女