Re: How can I extract just the last(i.e. most current) entry from
Posted in 2003
Topics: Stored Procedures & SPL
Michael Krzepkowski wrote: > JeffC wrote: > > >>Consider the following: >> >>There are multiple records in a table that contain the following >>fields/values: >> >>userid phone orderdate orderstatus >>a1234567 111-222-3333 2001-05-18 Completed >>a1234567 111-222-3333 2002-02-02 Completed >>a1234567 111-222-3333 2003-03-05 Pending Completion >> >>Using PL/SQL I'd like to get just the record with the most recent >> > > There is no PL/SQL in Informix. SPL? Cheers, -- Mark. +----------------------------------------------------------+-----------+ | Mark D. Stock mailto:mdstock@MydasSolutions.com |//////// /| | Mydas Solutions Ltd http://MydasSolutions.com |///// / //| | +-----------------------------------+//// / ///| | |We value your comments, which have |/// / ////| | |been recorded and automatically |// / /////| | |emailed back to us for our records.|/ ////////| +----------------------+-----------------------------------+-----------+ sending to informix-list
> >>userid phone orderdate orderstatus
> >>a1234567 111-222-3333 2001-05-18 Completed
> >>a1234567 111-222-3333 2002-02-02 Completed
> >>a1234567 111-222-3333 2003-03-05 Pending Completion
Hi
If you are after a simple query that returns the record(s) with the
latest order date in the system, this will do it;
select * from table_name where orderdate = (select max(orderdate) fromtable_name);
This will return more than one record if there are multiple orders on
any one day (which you would expect). If you want an absolute latest
order then use max(order_serial_no) or turn orderdate into a high
precision datetime data type.
HTH
Gerry