How do I select last 5 rows in a table without sor

2019-01-07 13:25发布

I want to select the last 5 records from a table in SQL Server without arranging the table in ascending or descending order.

20条回答
The star\"
2楼-- · 2019-01-07 14:21

Try this, if you don't have a primary key or identical column:

select [Stu_Id],[Student_Name] ,[City] ,[Registered], 
       RowNum = row_number() OVER (ORDER BY (SELECT 0))    
from student
ORDER BY RowNum desc 
查看更多
劫难
3楼-- · 2019-01-07 14:22

Last 5 rows retrieve in mysql


This query working perfectly

SELECT * FROM (SELECT * FROM recharge ORDER BY sno DESC LIMIT 5)sub ORDER BY sno ASC

or

select sno from(select sno from recharge order by sno desc limit 5) as t where t.sno order by t.sno asc
查看更多
登录 后发表回答