Almost everyone have met this subquery ERROR:
This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
and every answer suggest us to replace subquery with left outer join
in this situation.
Supporting limit subquery with in operation is a nice-to-have feature because lots of subqueries are used with in
operator, but why MySQL development group decide not to bring it to MySQL, is there any reasons that makes limit with these operator in a subquery dangerous or bad performance?
On Nov 30th 2016, as Mysql 8.0 latest beta draft documentation, MySQL still not support this kind of subquery.
http://dev.mysql.com/doc/refman/8.0/en/subquery-errors.html
Here are my comments on each scenario listed in that link that you sent:
The only possible scenario which I could possibly think of to limit the results of a subquery is to bring just a data sample, like if you want to bring a count of errors in a log or something and you just want a column for random sample (ex: [PROGRAM][LOG COUNT][ERR COUNT][ERR EXAMPLE])... in this very rare case, I would understand the usage of limiting the result of a subquery but for this you can use some group by function such as MIN()
or MAX()
and definitely not through LIMIT
.
To more directly answer just the main question "why doesn't MySQL support 'LIMIT & IN/ALL/ANY/SOME subquery'" - because if you are trying to select data like data in (select data... LIMIT...)
are you basically trying to do data in (some random data)
, since the LIMIT
will prevent some rows from showing up in the subquery results and there's no way to determine which ones.
Anyway, if you find any scenario that you think you need to limit the results of a subquery and it's not to just bring a sample of data - think again, something is probably wrong with your logic; ask here if it's the case :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With