Selection with various differences conditions (SQLSERVER)

Asked

Viewed 215 times

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 don’t have a certain set interval and the ids are selected by checkbox in html, ie I can have N ids. There is some syntax in SQL or Sqlserver that can improve this type of query?

2 answers

4


You can use the IN, would look like this:

SELECT * FROM table WHERE id NOT IN (15, 17, 23);

1

You can use the NOT IN:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.