Link to home
Start Free TrialLog in
Avatar of yadavricky
yadavrickyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How can we retrieve last N rows inserted in the table

hi
can anybody tell that how can we retrieve last N rows inserted in the table ?
 
PROBLEM - we have a table with suppose 30-40 lakh rows. we want to run a select query to retrieve data from only last 1 lakh rows that were inserted.
Avatar of vinodsnair2001
vinodsnair2001
Flag of India image

SELECT TOP 100000 column-list
from table-name
ORDER BY Timestamp or Identity column DESC
here you can use either timestamp column or if the column has an identity column then can use it
Please mark YES if this was helpful
ASKER CERTIFIED SOLUTION
Avatar of Shaju Kumbalath
Shaju Kumbalath
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of apexpert
apexpert

try this you can access last N rows :

select top N ( select * from tablename1 order by id desc ) from tablename1
Avatar of awking00
What is the structure of the table? Are there any fields with date or timestamp that would determine when the rows were entered? If not, what criteria would you use to determine "last"?