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