您好,欢迎访问一九零五行业门户网

SQL语句技巧:查询存在一个表而不在另一个表中的数据记录

方法一(仅适用单个字段) 使用 not in ,容易理解,效率低 select a.id from a where a.id not in (select id from b) 方法二(适用多个字段匹配) 使用 left join...on... , b.id isnull 表示左连接之后在b.id 字段为 null的记录 select a.id from a left jo
方法一(仅适用单个字段)
使用 not in ,容易理解,效率低
select a.id from a where a.id not in (select id from b)
方法二(适用多个字段匹配)
使用 left join...on... , b.id isnull 表示左连接之后在b.id 字段为 null的记录
select a.id from a left join b on a.id=b.id where b.id is null 
方法三(适用多个字段匹配)
select * from b where (select count(1) as num from a where a.id = b.id) = 0
方法四(适用多个字段匹配)
select * from a where not exists(select 1 from b where a.id=b.id)
同步发表于我的个人网站:http://www.zuowenjun.cn/post/2014/10/09/54.html
其它类似信息

推荐信息