tableA
|column1 | column1 |column3 |
tableb
|column1 | column1 |column3 |
要查询 tableA
的数据,条件是是 tableA.column1
不在 tableB
的 tableB.column2
中
也就是要得到类似以下语句的效果(not in
效果不完全等同于 not exists
, 如果子查询中出现空记录, 则整个查询语句不会返回数据)
SELECT
a.*
FROM
tableA a
WHERE
a.column1 not in (
SELECT column2 FROM tableB
)
可以使用如下语句来实现
SELECT
a.*
FROM
tableA a
WHERE
NOT EXISTS(
SELECT b.column2 FROM tableB b WHERE a.colunm1=b.column2
)
以上只是两张表的情况, 其实在多张表的连接查询中也是比较好用的. 以上写法同样适用于exists
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有