Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select last 3 rows of sql table

Tags:

mysql

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?

like image 593
Amir Sadegh Avatar asked Feb 21 '26 01:02

Amir Sadegh


2 Answers

Try this:

SELECT * FROM (
  SELECT * FROM reset ORDER BY id DESC LIMIT 3
) as r ORDER BY id
like image 99
null.point3r Avatar answered Feb 27 '26 08:02

null.point3r


I hope this help your problem

select * from
(
select *  from reset 
order by id DESC LIMIT 3
 ) t
order by id ASC 
like image 39
errorintheapplication Avatar answered Feb 27 '26 10:02

errorintheapplication