GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Database  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 132 of 139    Print  
Recent row entered
I have a very unusual question, how can one check which is the recent row added to a table?


  
Total Answers and Comments: 7 Last Update: August 26, 2009     Asked by: akbarali 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: biswaranjanbehera
 
We can select the recent row enrtered by using the query below.
suppose the table name is employee;
then.
select * from employee where rowid=(select max(rowid) from employee).
This works fine because rowid is assigned for each and every record and in accending order. So the recent record's rowid is the man (rowid). Please send feedback with any concern.

Above answer was rated as good by the following members:
harit79, laura_love, sreekanth009, sandeep549
July 01, 2008 11:23:36   #1  
seemu123 Member Since: May 2008   Contribution: 15    

RE: Recent row entered
You can check it with the help of

SCOPE_IDENTITY( ) function in SQL server 2000 or 2005


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
August 06, 2008 01:27:12   #2  
biswaranjanbehera Member Since: July 2008   Contribution: 4    

RE: Recent row entered
We can select the recent row enrtered by using the query below.
suppose the table name is employee;
then.
select * from employee where rowid (select max(rowid) from employee).
This works fine because rowid is assigned for each and every record and in accending order. So the recent record's rowid is the man (rowid). Please send feedback with any concern.

 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 1Overall Rating: +2    
August 06, 2008 01:33:03   #3  
biswaranjanbehera Member Since: July 2008   Contribution: 4    

RE: Recent row entered
We can get the recent row entered by the help of this query below.

select * from employee where rowid (select max(rowid) from employee);
because the rowid for the recent row entered in a table is always maximum (though it is stored in accending order).


thanks & regards
Biswaranjan

 
Is this answer useful? Yes | No
August 06, 2008 07:25:49   #4  
mv_sivavardhan Member Since: August 2008   Contribution: 6    

RE: Recent row entered
select scope_identity
will return the identity value of the last row inserted

 
Is this answer useful? Yes | No
October 11, 2008 15:44:06   #5  
malapati Member Since: October 2008   Contribution: 13    

RE: Recent row entered

select *from<table name> where rowid (select max(rowid) from <table name>);


for eg:if we are having a table called "CUSTOMER" then;


select *from customer where rowid (select max(rowid) from customer); will show the recent entered record

 
Is this answer useful? Yes | No
March 23, 2009 06:27:01   #6  
Ashish4oracle Member Since: March 2009   Contribution: 1    

RE: Recent row entered
You can try this one query. I am sure this is working fine

select * from tablename where rowid (select max(rowid) from tablename);

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
August 26, 2009 12:44:41   #7  
dachi316 Member Since: August 2009   Contribution: 1    

RE: Recent row entered
SCOPE_IDENTITY() would be a better option to get the most recently added row as the primary key for a table may not necessarily be an auto-incrementing variable. Therefore max(rowid) would not be the optimal solution in that case.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape