Empty IN clause parameter list in MySQL

后端 未结 9 1034
攒了一身酷
攒了一身酷 2020-11-30 08:45

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

For example:

SELECT user WHERE id IN ();

Will MySQL

9条回答
  •  醉话见心
    2020-11-30 08:56

    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.

提交回复
热议问题