MySQL的"NOT IN"询问 [英] MySQL "NOT IN" query

查看:81
本文介绍了MySQL的"NOT IN"询问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个简单的查询以抛出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

这将引发语法错误. Google搜索使我进入了一个论坛,那里的人们说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,必须有一个set,请改用以下语法:

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的"NOT IN"询问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆