How to FETCH the second Last record in a table without any identity column?

 Posted by vishalneeraj-24503 on 2/3/2015 | Category: Sql Server Interview questions | Views: 1395 | Points: 40
Answer:

We have to write below query:-
declare @count int; 

select @count = count(*) from tableName;

select * from tableName
except
select top(@count - 2) * from tableName;

without using any identity column and ORDER BY clause we can get last 2 records from a table by using above code.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response