34,588
社区成员
发帖
与我相关
我的任务
分享
----------------------------------------------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2011-04-25 15:37:36
-- Verstion:
-- Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
-- Jul 9 2008 14:43:34
-- Copyright (c) 1988-2008 Microsoft Corporation
-- Enterprise Evaluation Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
--
----------------------------------------------------------------
--> 测试数据:[a]
if object_id('[a]') is not null drop table [a]
go
create table [a]([a] int,[b] int,[c] int,[d] int)
insert [a]
select 1,2,3,4 union all
select 2,3,4,5 union all
select 3,4,5,6
--> 测试数据:[b]
if object_id('[b]') is not null drop table [b]
go
create table [b]([a] int,[b] int,[c] int,[d] int)
insert [b]
select 1,2,3,4 union all
select 3,4,5,6
--------------开始查询--------------------------
select * from a where checksum(*) not in(select checksum(*) from b)
----------------结果----------------------------
/* a b c d
----------- ----------- ----------- -----------
2 3 4 5
*/
select * from a表
except
select * from b表