Home » SQL & PL/SQL » SQL & PL/SQL » Last Record
Last Record [message #9701] Tue, 02 December 2003 02:21 Go to next message
Cindreen Clarence
Messages: 41
Registered: March 2003
Location: Bangalore
Member
Hi,
How 2 retrieve the last record of a table?
Thanx,
Arshad
Re: Last Record [message #9704 is a reply to message #9701] Tue, 02 December 2003 02:28 Go to previous messageGo to next message
Adrian Billington
Messages: 139
Registered: December 2002
Senior Member
We see this question so many times. How do you define the last record ? If you are meaning the last record to be "the last record inserted", then if you take time to think about it, it is a nonsensical question, especially if you are storing your data as a heap.

The reason I say it is nonsensical is that Oracle in no guarantees to return records in the order they were inserted. Instead, you have your own control over it with the ORDER BY clause in your SQL. You need to determine which column in your table represents the order in which data is inserted, then use ORDER BY to ensure the resultset is sorted:-

SELECT something
FROM   table
ORDER  BY
       my_order_column_that_represents_order_of_insert;


Regards
Adrian
Re: Last Record [message #9747 is a reply to message #9704] Tue, 02 December 2003 21:34 Go to previous message
Cindreen Clarence
Messages: 41
Registered: March 2003
Location: Bangalore
Member
Gee thanx for the trouble u tuk to answer my nonsensical Q!!
Actually even i know that its a baseless Q, but what to do,these are Qs asked by interviewers in beeg beeg companies. i had a hell of time trying to explain to the interviewer that there is no ordering as such in an Oracle table.But he was adamant that i give him a Query Statement that would retrieve the last record of the table!
so thats the history of my Q.
Thanx.
Previous Topic: urgent
Next Topic: Doubts (Vry Urgent!)
Goto Forum:
  


Current Time: Fri Apr 26 03:13:06 CDT 2024