Home » SQL & PL/SQL » SQL & PL/SQL » Selecting last record
Selecting last record [message #6425] Wed, 16 April 2003 10:12 Go to next message
Simon
Messages: 60
Registered: December 1998
Member
Hi,

I want to select the last record in a table.

Something like:

select asset_no from products where 'last record'

but i dont know how I would do the where clause.

Any ideas?
Re: Selecting last record [message #6427 is a reply to message #6425] Wed, 16 April 2003 10:18 Go to previous messageGo to next message
Mike
Messages: 417
Registered: September 1998
Senior Member
Hi Simon,

In Oracle there is nothing like a "last record". If you want to get the last inserted or updated column it's up to you to add a column for either a sequence or a date value.

If you could be more precise for what exactly you need it I may give you some other workarounds.

HTH
Mike
Re: Selecting last record [message #6428 is a reply to message #6425] Wed, 16 April 2003 10:22 Go to previous messageGo to next message
Simon
Messages: 60
Registered: December 1998
Member
Hi thanks for the reply.

I have an ASP page which allows me to create a new product record. A trigger and sequence is set up to generate a new asset_no which is the primary key of the products table.

What i want to do is when the page is submitted and the new record is created it displays the new asset_no which has just been created.

So I am not sure how this can be done.

Hope this makes a bit more sense
Re: Selecting last record [message #6429 is a reply to message #6425] Wed, 16 April 2003 10:23 Go to previous messageGo to next message
Art Metzer
Messages: 2480
Registered: December 2002
Senior Member
quote from Simon:
----------------------------------------------------------------------
Hi,

I want to select the last record in a table.

Something like:

select asset_no from products where 'last record'

but i dont know how I would do the where clause.

Any ideas?

----------------------------------------------------------------------
What do you mean by "last record"?

I hope you don't mean the last record inserted in the table....

The only way to find the last record inserted into a table is for you to add a timestamp or sequence column to the table in question, and query off of that.

Good luck,

A
Re: Selecting last record [message #6435 is a reply to message #6425] Wed, 16 April 2003 15:59 Go to previous message
speedy_omen
Messages: 1
Registered: April 2003
Junior Member
Create a sequence
Create a trigger on the table for the id

then insert in the table without the id field (will be generated by the trigger)

then

Select sequencename.currval from dual

do this on the same connection as the insert and you get the inserted id
Previous Topic: oracle Triggers
Next Topic: sql stmt precedence of functions and how they are evaluated.
Goto Forum:
  


Current Time: Tue Apr 16 12:20:11 CDT 2024