I'm using this statement in SQLServer and it works fine:
SELECT TOP 1000 *
FROM [SomeTable]
It gives me the TOP 1000
records from SomeTable
, now which keyword should I use instead of Top
if I need the Bottom 1000
records from the table?
This question is related to
sql-server-2008
To get the bottom 1000 you will want to order it by a column in descending order, and still take the top 1000.
SELECT TOP 1000 *
FROM [SomeTable]
ORDER BY MySortColumn DESC
If you care for it to be in the same order as before you can use a common table expression for that:
;WITH CTE AS (
SELECT TOP 1000 *
FROM [SomeTable]
ORDER BY MySortColumn DESC
)
SELECT *
FROM CTE
ORDER BY MySortColumn
You must sort your data according your needs (es. in reverse order) and use select top query
Source: Stackoverflow.com