这里主要不是想用联合查询, 虽然下面 select * from A where A.id in(select B.id from B) 可以用联合查询来做,但是如果是下面的情况 select * from A where A.id not in(select B.id from B) 又该怎么做呢?
试试 select * from A where id in(select id from B)
呵呵。我自己找到答案了。可以用以下做法: select A.* from A left join B on A.id=B.id where isnull(A.id)=1
还可以这样 select * from A left join B on A.id=B.id where B.id is null
虽然下面
select * from A
where A.id in(select B.id from B)
可以用联合查询来做,但是如果是下面的情况
select * from A
where A.id not in(select B.id from B)
又该怎么做呢?
select * from A
where id in(select id from B)
select A.* from A left join B
on A.id=B.id
where isnull(A.id)=1
select * from A left join B on A.id=B.id where B.id is null