Hi,
in case you ever need to get the associated data to that record, say :
Id, MyDate, Price
and you want the last price at or before certain date then :

select MyTable.Id, MyTable.Price
into cursor PricesUpToDate
from (
        Select Id, max(MyDate)
        from MyTable
        where MyDate <= TopDate
        ) Tops
inner join MyTable
        on MyTable.Id = Tops.Id
                and MyTable.MyDate = Tops.MyDate


Garry Bettle wrote:
> Doh!
> 
> Sorry, please move along, nothing to see here:
> 
> SELECT SelectId, MAX( DTime) FROM DBF() TO SCREEN GROUP BY 1
> 
> Boy, did I pick a bad week to stop sniffing glue.
> 
> G.
> 
> On Jan 24, 2008 5:18 PM, Garry Bettle <[EMAIL PROTECTED]> wrote:
> 
>> Howdy all,
>>
>> Hope this email finds everyone well - roll on the weekend.
>>
>> I'm trying to work out how to select the latest row from a database, based
>> on the latest datetime field.
>>
>> So, if I have something like:
>>
>> Id        Datetime
>> -------   -------------------
>> 1412554   24/01/2008 14:09:10
>> 1412554   24/01/2008 14:09:24
>> 1412554   24/01/2008 14:09:31
>> 1519040   24/01/2008 14:04:29
>> 736856    24/01/2008 14:00:50
>> 736856    24/01/2008 14:01:05
>> 736856    24/01/2008 14:01:26
>> 736856    24/01/2008 14:08:17
>> 805539    24/01/2008 13:48:46
>> 805539    24/01/2008 13:55:03
>> 805539    24/01/2008 13:56:16
>> 805539    24/01/2008 14:04:37
>> 805539    24/01/2008 14:06:12
>> 805539    24/01/2008 14:06:54
>> 805539    24/01/2008 14:08:09
>> 961254    24/01/2008 13:42:32
>> 961254    24/01/2008 13:44:23
>> 961254    24/01/2008 13:44:59
>> 961254    24/01/2008 13:45:13
>> 961254    24/01/2008 13:46:10
>>
>> I would like to have:
>>
>> Id            Datetime
>> -------       -------------------
>> 1412554       24/01/2008 14:09:31
>> 1519040       24/01/2008 14:04:29
>> 736856        24/01/2008 14:08:17
>> 805539        24/01/2008 14:08:09
>> 961254        24/01/2008 13:46:10
>>
>> Many thanks!
>>
>> Cheers,
>>
>> Garry
>>


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to