8

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?

Matt
  • 14,906
  • 27
  • 99
  • 149
Ian Newson
  • 7,679
  • 2
  • 47
  • 80

5 Answers5

11

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).

ughai
  • 9,830
  • 3
  • 29
  • 47
Giorgi Nakeuri
  • 35,155
  • 8
  • 47
  • 75
0

Use NULL

SELECT *
FROM Products
WHERE ProductID IN (NULL)

As this will return nothing

Matt
  • 14,906
  • 27
  • 99
  • 149
-1

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

SELECT *
FROM Products
WHERE ProductID IN (-1)
ughai
  • 9,830
  • 3
  • 29
  • 47
VitaliG
  • 52
  • 3
-1

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.

jarlh
  • 42,561
  • 8
  • 45
  • 63
viktor
  • 405
  • 1
  • 5
  • 6
-1
SELECT *
FROM Products
WHERE ProductID IN (SELECT '')

Another possible way.

DNac
  • 2,663
  • 8
  • 31
  • 54