yadavricky
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this you can access last N rows :
select top N ( select * from tablename1 order by id desc ) from tablename1
select top N ( select * from tablename1 order by id desc ) from tablename1
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"?
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