以下是引用lhj2005在2007-11-20 13:15:27的发言:
我原意是这样的:
预置条件 a表,c表,d表,e表
a表是个存在的表格,而b表是通过SQL语句查询a,c,d表得到的结果作为的临时表格,并不是建立临时表
(select * from c,d,e) as b
你开始又不说清楚,人家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 陈六 女