求助:
两个表a和b,两表中的数据几乎相同,b表比a表多几十条数据,求找出多出的数据的语句
两表中的字段是 ID ,NAME,SEX
select * from b
where b.ID not in (select ID from a)
请求其他语句!(注:b表是临时表,是通过其他查询的临时表)
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
*/