mysql 语法不等于多个值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12111451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql syntax on not equal many values
提问by lgt
I'm trying to get the right syntax for the following case?
我正在尝试为以下情况获得正确的语法?
SELECT *
FROM wp_posts AS p
WHERE post_type = 'post'
AND post_status = 'publish'
AND ID <> 5616,1095,1357,271,2784,902
ORDER BY post_title DESC
回答by podiluska
Instead of <>
, you can use NOT IN (5616,1095...)
相反<>
,您可以使用NOT IN (5616,1095...)
SELECT *
FROM wp_posts AS p
WHERE post_type = 'post'
AND post_status = 'publish'
AND ID NOT IN (5616,1095,1357,271,2784,902)
ORDER BY post_title DESC
回答by hims056
SELECT * FROM wp_posts AS p WHERE post_type = 'post'
AND post_status = 'publish' AND
ID NOT IN (5616,1095,1357,271,2784,902) ORDER BY post_title DESC
回答by Samuel
The <>
operator compares a single left and right argument to see if they are not equal. In your case you have one left hand argument that needs to be checked (I assume) to see if the ID
is none of the values on the right. Therefore you should use ID NOT IN (5616,1095,1357,271,2784,902)
该<>
运营商比较单一的左边和右边的参数,看看他们是不相等的。在您的情况下,您有一个需要检查的左手参数(我假设)以查看是否ID
不是右侧的任何值。因此你应该使用ID NOT IN (5616,1095,1357,271,2784,902)