I have a problem about keeping the order in the subquery with WHERE IN
clause.
I am using this following query with 2 tables listed below.
SELECT * FROM user_list WHERE uid IN (
SELECT uid from user_history ORDER BY timestamp DESC
) LIMIT 5
Table - user_list
uid name surname
001 Alpha Apples
002 Bravo Butter
003 Charlie Charlie
004 Delta Duff
005 Echo Edward
Table - user_history
uid timestamp
003 0000-00-00 00:00:00
001 0000-00-00 00:00:01
005 0000-00-00 00:00:02
The expected result is (ORDER BY timestamp DESC
)
005 Echo Edward
001 Alpha Apples
003 Charlie Charlie
But its result as this
001 Alpha Apples
003 Charlie Charlie
005 Echo Edward
The ORDER BY
clause is ignored and still order by primary key (uid
).
I am wondering is there any way to keep the order from subquery?