Home » SQL & PL/SQL » SQL & PL/SQL » How to get last row from a table in Oracle through SQL query
How to get last row from a table in Oracle through SQL query [message #28240] Thu, 11 December 2003 00:14 Go to next message
ashok
Messages: 32
Registered: July 2000
Member
Could you please any one help on my doubt.

"How to get last row from a table in Oracle through SQL query"
Re: How to get last row from a table in Oracle through SQL query [message #28242 is a reply to message #28240] Thu, 11 December 2003 00:41 Go to previous messageGo to next message
Ultra
Messages: 98
Registered: November 2003
Member
What do you mean with the last row ?
Last row inserted in the table
or last line of query sorted by a column ?

For the firt one, no idea.
Rowid can be helpfull but no warranty,
because rowid are not always contigous
but sometimes it's

For the second one (really easy)
If you want the last row , you mean the
row with the highest value for COL1
(if it's unique)
try this

select * from TABLE1 where COL1 in
(select max(COL1) from TABLE1)
Re: How to get last row from a table in Oracle through SQL query [message #28244 is a reply to message #28240] Thu, 11 December 2003 02:59 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
please have a look  [url=http://www.orafaq.net/cgi-bin/msgboard/view.cgi?board=sql&message=20806&query=rowid%20Mahesh]here[/url] 

Re: How to get last row from a table in Oracle through SQL query [message #28245 is a reply to message #28244] Thu, 11 December 2003 03:14 Go to previous messageGo to next message
Mike
Messages: 417
Registered: September 1998
Senior Member
Mahesh,

It maybe that in the case of small table your solution works BUT THERE IS NO GARANTY FOR IT.

And if your query should be executed in parallel it will certainly not be the case.

The only reliable way to get the first row of a table is to define what you mean by first and then order your data by this defintion and take the first row.

That's it.
Re: How to get last row from a table in Oracle through SQL query [message #28247 is a reply to message #28240] Thu, 11 December 2003 03:45 Go to previous messageGo to next message
Thiru
Messages: 1089
Registered: May 2002
Senior Member
also have a look here -->

Re: How to get last row from a table in Oracle through SQL query [message #28250 is a reply to message #28245] Thu, 11 December 2003 04:10 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Definatly agree with you.
This is NOT a solution.
the intention was to look into the concept behind insertion / deletion of records with respect to rowid allocation.

Re: How to get last row from a table in Oracle through SQL query [message #28314 is a reply to message #28240] Mon, 15 December 2003 18:14 Go to previous message
Yogeshwar Sharma
Messages: 2
Registered: December 2003
Junior Member
Hi!

you can use this SQL statement to get last row from a table.

select col1,col2,col3... from
(select col1,col2,col3...,rownum pos from table_name)
where pos = (select max(pos) from (select col1,col2,col3...,rownum pos from table_name))

where col1,col2..are the fields of the table and pos will give u the position of a record.

You can use this SQL to get record at any position in a table

Cheers.
Previous Topic: problem Tuning SQL Oracle 8
Next Topic: VARRAY Initialization
Goto Forum:
  


Current Time: Fri May 16 13:43:47 CDT 2025