Sloganho Sloganho - 5 months ago 10
SQL Question

MySQL IN condition gets results with always false condition

I need a condition that when used with an IN condition, it won't return any results. I initially thought this would work, but it still gives back results:

SELECT * FROM MyTable WHERE myColumn IN (SELECT FALSE FROM dual WHERE FALSE);


Is there a condition I could put in the IN condition to have it always return no results?

NOTE: This is being used in a PHP function where the column could be any type with any value.

Answer

Instead of false use null. When null occurs in an expression, that always leads to a overall null value (there are some exceptions, like with is null but not in this context of in):

... in (select null from dual where null)
Comments