我试图实现类似的东西:
select column1 column2 from table1
where column1 and column2 not in (select column1 column2 from table2)
当然这是错误的,但如何正确构建它呢?非常感谢您的帮助!
朱莉
最佳答案
MySQL 支持 in
和 not in
的元组:
select column1 column2
from table1
where (column1, column2) not in (select column1 column2 from table2);
也就是说,我更喜欢 jarlh
的解决方案,原因有二(使用 not exists
):
- 首先,
不存在
更合理地对待NULL
值。 - 并非所有数据库都支持
in
和not in
的元组。我使用许多不同的数据库,所以我更喜欢更通用的语法。
关于mysql - 比较来自 2 个 sql 查询的一对列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48459065/