例如:兩個表:t1, t2 ,查詢在表t1中存在,而在表t2中不存在的記錄。
假設以id字段爲關聯字段。
方法1:需要兩個表的字段完全一致
select *
from t1
minus
selecct * from t2
方法2:
select * from t1
where not exists(select 1 from t2 where t1.id=t2.id)
方法3:
select * from t1
where id not in(select id from t2)
方法4:需要t2.id不能爲空
select t1.*
from t1
left join t2 on t1.id=t2.id
where t2.id is null