F
F
fruityiceangel2014-02-19 16:26:58
SQL
fruityiceangel, 2014-02-19 16:26:58

How to select latest records from table without sorting?

You need to select the last 10 records from the table without using sorting. MS SQL Server 2012

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Kind, 2014-02-19
@fruityiceangel

Good afternoon,
Query:
SELECT ID FROM `components` WHERE
ID BETWEEN (SELECT MAX(ID) FROM components)-10 AND (SELECT MAX(ID) FROM components)
At least MySQL does not use sorting, maybe. and in MSSQL will give a ride. ID - index, auto-increment. But when deleting records, you will have to renumber records that are larger than the one being deleted, but there is one simple request (set id=id-1)
Good luck!

M
Max, 2014-02-19
@AloneCoder

In general, the answer to your question is that it is not possible, even if you use a clustered index there is still no guarantee that it will be used.

F
fruityiceangel, 2014-02-19
@fruityiceangel

there is a table with columns: id, components, Created_date . You need to select the last ten entries added to it, that is, the last 10 components

F
fruityiceangel, 2014-02-19
@fruityiceangel

You can definitely do it, but here's how...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question