Alex Rivera | Logout

Empty IN clause parameter list in MySQL

Asked 2012-11-03T14:51:04.737
128

What happens when you do a SQL query where the IN clause is empty?

For example:

SELECT user WHERE id IN ();

Will MySQL handle this as expected (that is, always false), and if not, how can my application handle this case when building the IN clause dynamically?

Edit
Report

1 Answer

13

The closest approximation of this query with valid syntax is:

SELECT user FROM tbl1 WHERE id IN (SELECT id FROM tbl1 WHERE FALSE);

which unconditionally returns an empty result set. The subquery in the bracket always returns an empty set, and no value can be found in an empty set, since an empty set contains no values.

answered 2012-11-03T14:58:46.787

Your Answer