How to retrieve last record from a table
for eg we have emp table from that i wan to retriew last inserted record without seeing or knowing how can i get it
How to retrieve last record from a table
for eg we have emp table from that i wan to retriew last inserted record without seeing or knowing how can i get it
Dear Friend,
Try this,
SELECT * FROM (
SELECT ROWNUM RN,A.* FROM TABLE_NAME A WHERE ROWNUM < (SELECT COUNT(*)+1 FROM TABLE_NAME) )
WHERE RN = (SELECT count(*) FROM TABLE_NAME)
Have a pleasant time.
Thank your for your query sreekumar.
What is the use of
WHERE ROWNUM < (SELECT COUNT(*)+1 FROM TABLE_NAME
in the above query.We can get output even without this where clause.
Last edited by krishnaindia2007; 12-24-2007 at 11:03 PM.
Dear Krishna,
Thank you for your reply.
Yes you are right, we can get the output without
WHERE ROWNUM < (SELECT COUNT(*)+1 FROM TABLE_NAME
Actually i was first selecting all rows using the above WHERE clause.
Now from this list, i was selecting the last row. COUNT(*)+1 was used
just to select all rows. Because if i use only count(*) then i might no get
the last row, thats why.
Well your query is right.
Thank you once again.
Have a pleasant time.
Merry Christmas
Try this also
select * from emp
minus
select * from emp where ROWNUM < (select max(rownum) from emp)
In sql server hw we will do that