Home » SQL & PL/SQL » SQL & PL/SQL » last record in a table
last record in a table [message #203265] Tue, 14 November 2006 09:29 Go to next message
gugan_ta
Messages: 17
Registered: April 2006
Location: trichy
Junior Member
hai to all!

heres my ?????????????

am having some n records in a table.How to retrive last record
from that table.

Thks>>>>>>>>>>>>>>>>>
Re: last record in a table [message #203266 is a reply to message #203265] Tue, 14 November 2006 09:31 Go to previous messageGo to next message
gbarbisan
Messages: 67
Registered: August 2006
Location: Treviso - Italy
Member
Last inserted? Do you have a SEQUENCE, so "last" means "with the max ID number"?

What do you mean with "last"?

[Updated on: Tue, 14 November 2006 09:31]

Report message to a moderator

Re: last record in a table [message #203267 is a reply to message #203265] Tue, 14 November 2006 09:43 Go to previous messageGo to next message
gugan_ta
Messages: 17
Registered: April 2006
Location: trichy
Junior Member


hai

thks 4 ur reply

the table contains 1k records. for eg
eid,ename,age,salary are field names.

my?
i wanna retrieve the 1000th record.
it doesnt contains any sequence. i do no the 1000th record in the table(say its completly not known i,e eid.....).
Re: last record in a table [message #203271 is a reply to message #203267] Tue, 14 November 2006 09:50 Go to previous messageGo to next message
gbarbisan
Messages: 67
Registered: August 2006
Location: Treviso - Italy
Member
Let's suppose you order all the records by EID.
And thus:

SELECT *
  FROM (SELECT A.*
          FROM YOUR_TABLE A
        ORDER BY A.EID DESC)
 WHERE ROWNUM < 2;

[Updated on: Tue, 14 November 2006 09:53]

Report message to a moderator

Re: last record in a table [message #203299 is a reply to message #203271] Tue, 14 November 2006 12:15 Go to previous message
Littlefoot
Messages: 20896
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
By the way, there's no "last record" or "first record" in relational database; unless records in a table contain timestamp (which shows time it was entered), a sequence (mentioned by @gbarbisan) or something similar, it is absolutely impossible to fetch "last" record you've entered into the table.
Previous Topic: put data from excel to database
Next Topic: Call procedure
Goto Forum:
  


Current Time: Tue Dec 06 06:27:49 CST 2016

Total time taken to generate the page: 0.17870 seconds