Home » SQL & PL/SQL » SQL & PL/SQL » How to retrieve last record in a table...
How to retrieve last record in a table... [message #255259] Tue, 31 July 2007 04:00 Go to next message
apps.suresh
Messages: 15
Registered: October 2006
Junior Member
Hi ,
here i got requirement for fetching the last record in a table. i m little bit confused on using rowid,rownum.
can any one solve/send the query for this.

thanks in advance.
Re: How to retrieve last record in a table... [message #255268 is a reply to message #255259] Tue, 31 July 2007 04:27 Go to previous messageGo to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
There is no "last record" in a relational database, unless you have something you can order the data by in the table.

When you have something to order the data by, then you can reverse the order and get the first row.

like

SELECT * FROM (
    select * from your_table
    order by your_order_column desc
) WHERE ROWNUM = 1


Re: How to retrieve last record in a table... [message #255272 is a reply to message #255268] Tue, 31 July 2007 04:38 Go to previous messageGo to next message
apps.suresh
Messages: 15
Registered: October 2006
Junior Member
My table does not having any constraints, how can i
Re: How to retrieve last record in a table... [message #255280 is a reply to message #255272] Tue, 31 July 2007 04:53 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
You can not.
Re: How to retrieve last record in a table... [message #255282 is a reply to message #255268] Tue, 31 July 2007 04:57 Go to previous messageGo to next message
Michel Cadot
Messages: 68733
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
But is the first in the reverse order the same as the last in requisite order?
/forum/fa/1986/0/
Regards
Michel
Re: How to retrieve last record in a table... [message #255289 is a reply to message #255282] Tue, 31 July 2007 05:10 Go to previous messageGo to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Quote:

But is the first in the reverse order the same as the last in requisite order?



Depends on the definition of "order" that is required. Very Happy

One could even make an approximated educated guess at which row might have (maybe) been possibly inserted (or updated) last with ORA_ROWSCN, when on Oracle 10.2.X.X.

Absolutely, definetely, completely no guarantee whatsoever that it works even remotely in the expected way, of course.

http://www.psoug.org/reference/pseudocols.html
Re: How to retrieve last record in a table... [message #255291 is a reply to message #255289] Tue, 31 July 2007 05:13 Go to previous message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
And it will only work when you commit after each insert. I think it's as close as you'll get when you have no timestamp column.

MHE
Previous Topic: Duplicate Record and Update
Next Topic: procedures
Goto Forum:
  


Current Time: Mon Feb 10 02:54:36 CST 2025