我正在尝试为以下情况获取正确的语法?
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
答案 0 :(得分:52)
您可以使用<>
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
答案 1 :(得分:2)
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
答案 2 :(得分:2)
<>
运算符比较单个左右参数,看它们是否相等。在你的情况下,你有一个需要检查的左手参数(我假设),看看ID
是不是右边的值。因此,您应该使用ID NOT IN (5616,1095,1357,271,2784,902)