How do you view the last record added to a table?

Questions by t_ahwaz

Showing Answers 1 - 36 of 36 Answers

Enrique

  • Sep 23rd, 2007
 

/*
 * How do you view the last record added to a table?
 */
Select Top 1 * from Emp Order By EmpID Desc

  Was this answer useful?  Yes

SQL> select  * from name;

no rows selected
  1* insert into name values('Girija')
SQL> /

1 row created.

SQL>  insert into name values('Srinu');

1 row created.

SQL> commit;

Commit complete.
  1* select * from name where rowid = (select max(rowid) from name)
SQL> /

NAME
--------------------
Srinu

We can accomplish this with rowid, below is an example of the query to get the latest inserted records from the table say emp

select * from emp outer where outer.rowid in (
select max(inner.rowid) b from emp inner);

  Was this answer useful?  Yes

udit

  • Jun 16th, 2014
 

your answer is wrong because min should be replaced with max.

  Was this answer useful?  Yes

Hi ahwaz,

In order to get Last record added to the table, you should first get an idea on table dattype..
1) Whether any sequence no in any column defined which will update when ever row is inserted.
2) will get by retrieving max rowid from the table

  Was this answer useful?  Yes

himabindu

  • Apr 16th, 2018
 

Why use rownum < 2?

  Was this answer useful?  Yes

Bobby

  • Apr 18th, 2018
 

rowid is pseudo column and it can change internally especially on transactional table

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions