Selection with various conditions of differences (SQLSERVER)

0

I wonder if there is any way to improve this selection:

SELECT * FROM table WHERE id <> 15 AND id <> 17 AND id <> 23 ... id <> N

I do not have a certain interval defined and the ids are selected by the checkbox in html, that is, I can have N ids. Is there any syntax in SQL or SQLServer that can improve this type of query?

    
asked by anonymous 09.10.2017 / 15:53

2 answers

4

You can use IN , it would look like this:

SELECT * FROM table WHERE id NOT IN (15, 17, 23);
    
09.10.2017 / 15:56
1

You can use NOT IN :

SELECT * FROM table WHERE id not in (15, 17, 23/*, N*/)
    
09.10.2017 / 15:56