select * ----在table1但不在table2中
from table1 as t1
where not exists(
select *
from table2 as t2
where t1.f1=t2.f1 and t1.f2=t2.f2 and ....
)
union
select * ----在table2但不在table1中
from table2 as t1
where not exists(
select *
from table1 as t2
where t1.f1=t2.f1 and t1.f2=t2.f2 and ....
)
from table1 as t1
where not exists(
select *
from table2 as t2
where t1.f1=t2.f1 and t1.f2=t2.f2 and ....
)
union
select * ----在table2但不在table1中
from table2 as t1
where not exists(
select *
from table1 as t2
where t1.f1=t2.f1 and t1.f2=t2.f2 and ....
)
本文介绍了一种使用SQL实现两个表之间的差集查询方法。通过NOT EXISTS子句来判断table1中的记录是否存在于table2中,反之亦然。最终返回那些只存在于其中一个表中的记录。
6718

被折叠的 条评论
为什么被折叠?



