SQL 字段对比问题
来源:百度知道 编辑:UC知道 时间:2024/05/30 03:37:25
两个表都只有一个 code 字段 A表和B表 B是A的子集 请问如何将A中不存在于B中的元素找出来
select * from A where code not in (select code from B)
select * from A where not exists (select 1 from B where code=A.code)
推荐使用第二种方式,因为exsits的执行效率要远远高于in的执行效率
以上,希望对你有所帮助!
select * from a where code not in (select code from b)