MySQL Query – How to Get Last X Rows Ordered by ASC?

MySQLorder-by

I want to select last X rows from a table, so what I did was:

SELECT * FROM table ORDER BY id DESC LIMIT 120

and it worked, but I want it to be ordered ascending, so I tried with:

SELECT * FROM table ORDER BY id DESC LIMIT 120 ORDER BY id ASC

expecting that it would reorder selected rows, but it didn't work.

So how can I achieve it?

Best Answer

Even this will work:

( SELECT ... ORDER BY ... LIMIT ... ) ORDER BY ...;

That is, no need in the syntax for the outer SELECT.