学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
 13 12
发新话题
打印

[求助]如何核对两表中的数据

[求助]如何核对两表中的数据

求助:
两个表a和b,两表中的数据几乎相同,b表比a表多几十条数据,求找出多出的数据的语句
两表中的字段是 ID ,NAME,SEX
select * from b
where b.ID not in (select ID from a)

请求其他语句!(注:b表是临时表,是通过其他查询的临时表)

TOP

create table #t1(
id int,
col1 int,
col2 int
)

insert into #t1 values(1,27,3)
insert into #t1 values(2,22,3)
insert into #t1 values(3,22,3)
insert into #t1 values(4,23,3)
insert into #t1 values(5,3,3)


create table #t2(
id int,
col1 int,
col2 int
)

insert into #t2 values(1,27,3)
insert into #t2 values(2,22,3)
insert into #t2 values(3,22,3)
insert into #t2 values(4,23,3)
insert into #t2 values(5,3,3)

--这两行是多出来的.
insert into #t2 values(7,23,3)
insert into #t2 values(8,3,3)

select b.* from #t1 a full join #t2 b on a.id=b.id where a.id is null

drop table #t1,#t2


/*
id col1 col2
----------- ----------- -----------
7 23 3
8 3 3
*/

我的msn: myfend@hotmail.com

TOP

拥有蓝天的白云,拥有你的我.

TOP

看不太懂
full 是什么?
有事无事都密我. MSN: cyyu_ryh@hotmail.co.jp E-mail: cyyu_ryh@yahoo.com

TOP

full
n.
全部, 完整

adj.
充满的, 完全的, 丰富的, 完美的, 详尽的, 丰满的

adv.
完全地, 整整, 十分

我的msn: myfend@hotmail.com

TOP

select b.* from #t1 a full join #t2 b on a.id=b.id where a.id is null

drop table #t1,#t2

为什么最后要删除两个表啊!!!

TOP

都是临时的,不删掉,留着做什么呢??占空间
一个天才顶不上十个笨蛋!
书山有路勤为径,学海无涯友相伴。
我的MSN和E-mail:mylover624@yahoo.com.cn

TOP

我原意是这样的:
预置条件 a表,c表,d表,e表

a表是个存在的表格,而b表是通过SQL语句查询a,c,d表得到的结果作为的临时表格,并不是建立临时表
(select * from c,d,e) as b

TOP

以下是引用purana在2007-11-15 12:54:05的发言:

full
n.
全部, 完整

adj.
充满的, 完全的, 丰富的, 完美的, 详尽的, 丰满的

adv.
完全地, 整整, 十分

哈哈...竟教起英国历史来了.

Repeat Life=Study; Until (death); //***>[B]欢 迎 光 临 我 的 博 客[/B]<***

TOP

to 8楼..
..不明白.
我的msn: myfend@hotmail.com

TOP

 13 12
发新话题