I am running the following SQL query:
SELECT * FROM cms_albums WHERE id IN (SELECT album_id FROM cms_albums_collections WHERE collection_id = 1 ORDER BY position ASC)
Now, assume the inner query
SELECT album_id FROM cms_albums_collections WHERE collection_id = 1 ORDER BY position ASC
returns the following:
album_id
"4"
"2"
This is the order that I want.
However the overall query will return:
id name
"2" "Second album"
"4" "First album"
I am assuming this is because the entries are in this order in the ‘cms_albums’ table.
Is there any way I can get my overall result in the order given by the inner query?
Thanks
Try this variation:
The order of the items in an IN list is lost, instead form a join, then you can apply the ordering you wanted.