Subject | RE: [firebird-support] How to get the latest record? |
---|---|
Author | bogdan |
Post date | 2011-12-18T10:19:02Z |
>> A table was created likeentry.
>>
>> create table Test(ITEM varchar(20) not null primary key, VAL
>> varchar(20));
>>
>> It is filled by records like
>>
>> (aaa_20111215, ...)
>> (aaa_20111215, ...)
>> (aaa_20111201, ...)
>> ...
>>
>> My question is how to select the record having the latest date for ITEM?
>>
>> The answer for the above records is (aaa_20111215, ...).
>>
>> Please write a sql to do this.
>Add an additional DATE column to the table, put an descending index on
>that column and use MAX to query the record with the most recent date
>With regards,I usually do it this way:
>Thomas Steinmaurer
Select first 1 test from test
where test starting with 'aaa_'
order by test descending
Presuming it is not always aaa_ in front of date part
Bogdan
* Firebird Foundation Committee Member
http://www.firebirdsql.org/en/firebird-foundation/
* Upscene Productions - Database Tools for Developers
http://www.upscene.com/
* My Blog
http://blog.upscene.com/thomas/index.php
[Non-text portions of this message have been removed]