SQL IN clause which is guaranteed to evaluate to false

157 views Asked by At

Is there any value which I can place in a SQL IN clause which will guarantee that the clause will evaluate to false?

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

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

5

There are 5 answers

6
Giorgi Nakeuri On BEST ANSWER

Replace with NULL. There is no better guarantee!

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

And this is kinda universal value for any type(as @zohar-peled mentioned).

0
VitaliG On

Put some initially invalid ProductID, e.g. -1.

SELECT *
FROM Products
WHERE ProductID IN (-1)
0
Matt On

Use NULL

SELECT *
FROM Products
WHERE ProductID IN (NULL)

As this will return nothing

0
viktor On

Try

SELECT *
FROM Products
WHERE ProductID IN (0)

I'm pretty sure that you don`t have product with ID=0

That will return false.

1
DNac On
SELECT *
FROM Products
WHERE ProductID IN (SELECT '')

Another possible way.