mysql> create temporary table temp ( ID int );
mysql> insert into temp select ID from cities order by population desc limit 5;
mysql> select a.* from cities a,temp b where a.ID=b.ID order by Name;
Temporary tables are discarded when the connection is closed, or they can be dropped manually. Temporary tables are not visible from other joins. The usual way would be (but not yet supported):
mysql> select * from cities where ID in (select ID from cities order by population desc limit 5) order by Name;
But the answer is:
ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
(Tried with 5.0.5)
source
share