找出不符合条件的 select t2.* from t2 join t1 on t1.id=t2.id and t1.uid<>t2.uid
select id from 表二 where id not in ( select 表二.id from 表一 right join 表二 on 表一.id = 表二.id and 表一.uid = 表二.uid where 表一.uid is null)
找出有id对应的uid不在表一中的id,一种方法Select Distinct ID from (Select * from 表二 A Where Not Exists (Select * from 表一 Where id=A.id And uid=A.uid)) B
测试数据 <mytable> id uid ----------- ---------- 1 001 1 002 1 005 1 006 2 003 2 008 2 009 2 005 <mytable2> id uid ------ ---------- 1 001 1 002 1 005 2 008 2 009 2 011查询 select distinct id from mytable2 where id not in ( select mytable2.id from mytable right join mytable2 on mytable.id = mytable2.id and mytable.uid = mytable2.uid where mytable.uid is null)结果 id ------ 1
select * from dbo.tb_1 t where ( ( select count(*) from dbo.tb_1 where id=t.id and uid in( select uid from dbo.tb_2 where id in (select id from dbo.tb_2 where uid='001') ) )= (select count(*) from dbo.tb_2 where id in (select id from dbo.tb_2 where uid='001') ) ) 谢谢各位大哥我的笨方法现在正在测试不知道可以不呵呵
select t2.* from t2 join t1 on t1.id=t2.id and t1.uid<>t2.uid
select 表二.id from 表一 right join 表二 on 表一.id = 表二.id and 表一.uid = 表二.uid
where 表一.uid is null)
(Select * from 表二 A Where Not Exists (Select * from 表一 Where id=A.id And uid=A.uid)) B
<mytable>
id uid
----------- ----------
1 001
1 002
1 005
1 006
2 003
2 008
2 009
2 005
<mytable2>
id uid
------ ----------
1 001
1 002
1 005
2 008
2 009
2 011查询
select distinct id from mytable2 where id not in (
select mytable2.id from mytable right join mytable2 on mytable.id = mytable2.id and mytable.uid = mytable2.uid
where mytable.uid is null)结果
id
------
1
select * from dbo.tb_1 t where (
(
select count(*) from dbo.tb_1
where id=t.id and uid in(
select uid from dbo.tb_2
where id in
(select id from dbo.tb_2 where uid='001')
)
)=
(select count(*) from dbo.tb_2
where id in
(select id from dbo.tb_2 where uid='001')
)
)
谢谢各位大哥我的笨方法现在正在测试不知道可以不呵呵