33

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
Mendoza
  • 82
  • 7
lgt
  • 1,024
  • 3
  • 18
  • 33

3 Answers3

90

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 
podiluska
  • 50,950
  • 7
  • 98
  • 104
5

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)

Samuel
  • 16,923
  • 6
  • 62
  • 75
4
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
Himanshu
  • 31,810
  • 31
  • 111
  • 133