Hi,
I want to know that how can we fetch last 2 records from the table having only one column name as 'ename' ?
Fetch last 2 records from the table
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
brunda kRank #3,804 · 389 reputationPosted Apr 15, 2012, 3:53 AM EDT
) dt
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 16, 2012, 8:04 PM EDT
It is quite difficult if your column data type is varchar.
but try,
select * from tableName where ename not in (select top ((select count(*) from tableName) - 2) ename from tableName)
above query is not working properly when your table contain duplicate value.
hope this help.
SenthilkumarRank #387 · 6.5K reputationPosted Apr 16, 2012, 9:01 PM EDT
1) SELECT TOP 2 * FROM (SELECT * FROM table_name WHERE ename ORDER BY ASC) tab
2) SELECT TOP 2 ename,
If you have any issues then reply me back.