I want to select the last 5 records from a table in SQL Server without arranging the table in ascending or descending order.
In SQL Server 2012 you can do this :
Declare @Count1 int ; Select @Count1 = Count(*) FROM [Log] AS L SELECT * FROM [Log] AS L ORDER BY L.id OFFSET @Count - 5 ROWS FETCH NEXT 5 ROWS ONLY;