Re: How to retrieve latest record when date and time are separate ?

From: Guido Konsolke <Guido.Konsolke_at_triaton.com>
Date: Wed, 9 Jul 2003 14:02:35 +0200
Message-ID: <1057752120.935500_at_news.thyssen.com>


"JN" <jirinej_at_volny.cz> schrieb im Newsbeitrag news:7e29a94a.0307090205.179bca49_at_posting.google.com...
> I record attendance of persons to table with these columns:
> PERSON_ID, DATE, TIME, CODE .
> Is it possible to write SQL query, which gives me latest record of
 all

> persons? Unfortunately, the DATE and TIME are separate columns.
> Thanks for any ideas.

Firstl of all: it's not too smart posting your question without enough infos. At least the table definition and a few rows of data...

Second: don't try to name your columns
using restricted words (date).

Anyway: a possible solution (I obviously don't know your rdbms version) would be:

select * from gktest;

PERSON_ID DAT TIME CODE
--------- -------- ----- ----------

        1 26.04.98 07:00 First one
        2 08.07.03 16:00 Second
        2 09.07.03 13:00 Third
        2 09.07.03 11:00 Fourth

select * from gktest
where dat=(select max(dat) from gktest)
and time=(select max(time) from gktest

          where dat=(select max(dat) from gktest)
         );

PERSON_ID DAT      TIME  CODE
--------- -------- ----- ----------
        2 09.07.03 13:00 Third

Some other ways do exist to reach your goal.

hth,
Guido Received on Wed Jul 09 2003 - 14:02:35 CEST

Original text of this message