SQL Server SELECT LAST N Rows Ask Question

SQL Server SELECT LAST N Rows Ask Question

This is a known question but the best solution I've found is something like:

SELECT TOP N *
FROM MyTable
ORDER BY Id DESC

I've a table with lots of rows. It is not a posibility to use that query because it takes lot of time. So how can I do to select last N rows without using ORDER BY?

EDIT

Sorry duplicated question of this one

ベストアンサー1

You can get MySQL, PostgreSQL, and SQLite (but not SQL Server) to select the last N rows with the following query:

select * from tbl_name order by id desc limit N;

おすすめ記事