SQL IN, which is guaranteed to be false

Is there any value that I can put in the SQL IN clause that guarantees that the clause will be evaluated as false?

SELECT * FROM Products WHERE ProductID IN (???) 

Is there anything that I could replace ??? with a guarantee that no rows will be returned?

+7
sql sql-server sql-in
source share
5 answers

Replace with NULL . There is no better guarantee!

Because no other value can be equal to NULL , even NULL .

And this is a kind of universal value for any type (as mentioned in @ zohar-peled).

+11
source share

Use NULL

 SELECT * FROM Products WHERE ProductID IN (NULL) 

Since it will not return anything

0
source share

Put some initially invalid ProductID, for example. -1 .

 SELECT * FROM Products WHERE ProductID IN (-1) 
-one
source share

Try

 SELECT * FROM Products WHERE ProductID IN (0) 

I am sure that you do not have a product with ID = 0

This will return false.

-one
source share
 SELECT * FROM Products WHERE ProductID IN (SELECT '') 

Another possible way.

-one
source share

All Articles