日期:2014-05-18 浏览次数:20689 次
select * from table1 a inner join table2 b on a.row1 = b.row1 and a.row2<>b.row2
------解决方案--------------------
select * from tb2 except select * from tb1
------解决方案--------------------
select * table2 a where not exists(select 1 from table1 b where a.col1=b.col1 and a.col2<>b.col2)
------解决方案--------------------
select * from tb2 a where not exists( select 1 from tb1 b where a.row1=b.row1 and a.row2=b.row2)
------解决方案--------------------
--> 测试数据:[table1]
if object_id('[table1]') is not null drop table [table1]
create table [table1]([row1] varchar(1),[row2] varchar(1))
insert [table1]
select 'a','o' union all
select 'b','p' union all
select 'c','q' union all
select 'd','s'
--> 测试数据:[table2]
if object_id('[table2]') is not null drop table [table2]
create table [table2]([row1] varchar(1),[row2] varchar(1))
insert [table2]
select 'a','o' union all
select 'b','p' union all
select 'c','x' union all
select 'd','y' union all
select 'e','z'
select * from table2 a--给table2取别名a
where not exists(select 1 from table1 b --给table1取别名a
where a.row1=b.row1 and a.row2=b.row2)
/*
row1 row2
c x
d y
e z
*/