The reason it does not work is because the external ORDER BY
cannot "see" tb1 - it sees the results of the internal subquery. Therefore, in the syntactically correct version of your query, you simply ORDER BY id
:
(SELECT tb1.id,tb1.bdate,tb1.jumpCard,tb1.publicImage,tb1.lastlogin FROM users AS tb1, online AS tb2 WHERE tb1.valid='1' AND tb1.sex='female' AND tb1.looking_for='male' AND tb1.id = tb2.member_id ORDER BY tb1.publicImage) ORDER BY id DESC
But as others point out, it could be easier written as a single request, ordered by id
source share