假设有两张表a和b,请求出表a与表b的差集(即只存在于表a中,不存在于表b的数据),2表共有字段为product_id,且product_id唯一。因为a表和b表的数据量极大,请不要使用:Select * from a where product_id not in (select product_id from b)。
select a.* from a left join b on a.product_id=b.product_id where b.product_id is null
我给你个建议,效率应该比较高的:
select * from a where not exists (select 1from b where a.product_id =b.product_id )
用except