Data:
Name Desc
Daman XXXX
Sam XXXX
Ram XXXX
Sun XXXX
Output:
Name Desc
Sun XXXX
Ram XXXX
There is no identity column. So far I have tried the below but its not helpful
select *, Rank() over(order by Name ) as [Rank] from testdaman
Data:
Name Desc
Daman XXXX
Sam XXXX
Ram XXXX
Sun XXXX
Output:
Name Desc
Sun XXXX
Ram XXXX
There is no identity column. So far I have tried the below but its not helpful
select *, Rank() over(order by Name ) as [Rank] from testdaman
order by (select null)
is not actually ordering your records, it is used because row_number()
requires an over
and order by
clause. No order is guaranteed, but you may find that the order is the same as the order the records were inserted in.
select top 2 *
from
(
select *, row_number() over (order by (select null)) [row]
from testdaman
) T
order by [row] desc
Original Answer - requires SQL Server 2012 and above
select *
from testdaman
order by (select null) -- No order applied, but offset requires the order by line
offset (select count(*)-2 from testdaman) rows fetch next (2) rows only