Amir Sadegh Amir Sadegh - 2 months ago 6
MySQL Question

Select last 3 rows of sql table

I want to select the last 3 rows of an sql table. I know I should use

SELECT * FROM table ORDER BY DESC LIMIT 3
, but the problem with this code is that it selects the rows from the end. For example, it selects 30, then 29, then 28. But, I need them in this format:
28, 29, 30
. Any suggestion?

Answer

Try this:

SELECT * FROM (
  SELECT * FROM reset ORDER BY id DESC LIMIT 3
) as r ORDER BY id