"Order by desc" in reverse order? "Order by desc" in reverse order? php php

"Order by desc" in reverse order?


SELECT * FROM (  SELECT ...   FROM ...   ORDER BY ID ASC   LIMIT 3) AS sq ORDER BY ID DESC

Think of it as working in two steps. First it executes the inner query: selects 3 records with lowest IDs. Then in the outer query it sorts them in descending order.


You can fetch the first three rows using a subquery and then reverse the order of these rows in an outer query:

SELECT *FROM(    SELECT *    FROM yourtable    ORDER BY ID    LIMIT 3) T1ORDER BY ID DESC


Nope, you aren't wrong. There are no difference for any sensible amount of data. Array_reverse is all right.
That's not a thing you have to be concerned too much of. Just use whatever you like more - for readability or other subjective reasons