选择最后3行的sql表

时间:2013-08-24 15:25:41

标签: mysql

我想选择sql表的最后3行。我知道我应该使用SELECT * FROM table ORDER BY DESC LIMIT 3,但这段代码的问题在于它从末尾选择行。例如,它选择30,然后是29,然后是28.但是,我需要这种格式:28, 29, 30。有什么建议吗?

6 个答案:

答案 0 :(得分:3)

试试这个:

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

答案 1 :(得分:3)

我希望这有助于解决您的问题

select * from
(
select *  from reset 
order by id DESC LIMIT 3
 ) t
order by id ASC 

答案 2 :(得分:1)

尝试这样的事情: -

  SELECT * FROM reset 
  WHERE username = '$table' ORDER BY id  ASC LIMIT (FOUND_ROWS() - 3), 3

答案 3 :(得分:0)

如下:

select * from (select * from table order by x desc limit 3) order by x;

答案 4 :(得分:0)

尝试

Select * from (SELECT * FROM Table_name ORDER BY Column_name DESC limit 0,3) as alias ORDER BY Column_name ASC;

答案 5 :(得分:0)

尝试本手册!

简单易用!!

Select * From tableName where 
PKCol=(select count(*) from tableName ) 
OR 
PKCol=(select count(*) from tableName )-1 
OR 
PKCol=(select count(*) from tableName )-2 
order by PKCol desc;