Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to do this - SQL

Re: How to do this - SQL

From: Mungo Henning <mungoh_at_itacs.strath.ac.uk>
Date: Thu, 01 Oct 1998 14:59:03 +0100
Message-ID: <36138AA7.265C0442@itacs.strath.ac.uk>


[attempting an answer here: fingers crossed I'm right! ]

Norazman Abu Sahir wrote:
>
> 1)How to write SQL statements that will fetch a certain field
> of the "last record in the table". Say table A which contains
> field named Dept. I realized before this in this newsgroup there is
> a way to get the "last 15" using rownum < 16. However how if I
> don't know how many records in the table but I just want to get
> the last one.

If I make an assumption here, I'll guess that you want the last record which was INSERTED into a table (with respect to time, that is)? Since the order of rows returned is haphazard when there is no ORDER BY clause present, be careful here. If you do need time-ordering, you need to consider an extra column on your table which contains some date information [can't think of any other way to timestamp a record insert... help anyone?] and then to get the "last" record you can use the function "max" (via a subquery) to return the single record.

>
> 2)The 2'nd question is regarding Oracle Report.
[sequence number query snipped]

Showing my ignorance of Oracle Reports, how's about "select sequence1.currval into myvariable from dual" as the work-around for this request?
>
>

Hope this is of help

Mungo Henning Received on Thu Oct 01 1998 - 08:59:03 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US