• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

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.
0
yadavricky
Asked:
yadavricky
2 Solutions
 
vinodsnair2001Commented:
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
0
 
Shaju KumbalathDeputy General Manager - ITCommented:
select * from (select * from table order by entered_dt desc) where rownum<=n ;
0
 
Shaju KumbalathDeputy General Manager - ITCommented:
SELECT *  FROM ( SELECT col1,col2, RANK() OVER (ORDER BY entered_dt desc) dt_rank
           FROM table )
WHERE dt_rank <= n;
0
 
apexpertCommented:
try this you can access last N rows :

select top N ( select * from tablename1 order by id desc ) from tablename1
0
 
awking00Commented:
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"?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now