Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql syntax on not equal many values

Tags:

mysql

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 
like image 802
lgt Avatar asked Aug 24 '12 14:08

lgt


People also ask

How do you write not equal condition in MySQL?

not equal to (<>, !=) operator. MySQL Not equal is used to return a set of rows (from a table) after making sure that two expressions placed on either side of the NOT EQUAL TO (<>) operator are not equal.

Is not equal to in SQL for multiple values?

Difference between SQL Not Equal Operator <> and != We can use both SQL Not Equal operators <> and != to do inequality test between two expressions. Both operators give the same output. The only difference is that '<>' is in line with the ISO standard while '!=

Can you use != In MySQL?

In MySQL, you can use the <> or != operators to test for inequality in a query. For example, we could test for inequality using the <> operator, as follows: SELECT * FROM contacts WHERE last_name <> 'Johnson';

Is <> and != The same in SQL?

Here is the answer – Technically there is no difference between != and <>. Both of them work the same way and there is absolutely no difference in terms of performance or result.


1 Answers

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  
like image 185
podiluska Avatar answered Sep 16 '22 11:09

podiluska