mysql syntax on not equal many values

后端 未结 3 1253
被撕碎了的回忆
被撕碎了的回忆 2020-12-28 16:08

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 &         


        
相关标签:
3条回答
  • 2020-12-28 16:25

    Instead of <> , you can use 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 
    
    0 讨论(0)
  • 2020-12-28 16:39

    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)

    0 讨论(0)
  • 2020-12-28 16:41
    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
    
    0 讨论(0)
提交回复
热议问题