MySQL quot;NOT INquot; query(MySQL“不在询问)
问题描述
我想运行一个简单的查询来抛出 Table1
的所有行,其中主列值不存在于另一个表 (Table2
) 的列中.
I wanted to run a simple query to throw up all the rows of Table1
where a principal column value is not present in a column in another table (Table2
).
我尝试使用:
SELECT * FROM Table1 WHERE Table1.principal NOT IN Table2.principal
这反而会引发语法错误.谷歌搜索把我带到论坛,那里有人说 MySQL 不支持 NOT IN
并且需要使用一些非常复杂的东西.这是真的?还是我犯了一个可怕的错误?
This is instead throwing a syntax error. Google search led me to forums where people were saying that MySQL does not support NOT IN
and something extremely complex needs to be used. Is this true? Or am I making a horrendous mistake?
推荐答案
要使用 IN,必须有一个集合,请改用以下语法:
To use IN, you must have a set, use this syntax instead:
SELECT * FROM Table1 WHERE Table1.principal NOT IN (SELECT principal FROM table2)
这篇关于MySQL“不在"询问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL“不在"询问


基础教程推荐
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在多列上分布任意行 2021-01-01