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