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“不在"询问


基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01