SQL IN clause which is guaranteed to evaluate to false

177 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 best solutions below

6
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
On

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

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

Use NULL

SELECT *
FROM Products
WHERE ProductID IN (NULL)

As this will return nothing

0
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
On
SELECT *
FROM Products
WHERE ProductID IN (SELECT '')

Another possible way.