Re: How to get the latest record from the database

Jon Frank <[email protected]> Mon, 21 Jun 2004 12:24:21 -0400
Newsgroups gmane.comp.web.webobjects.devel,gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
in EOModeler you can create a fetch spec like normal (as if you were 
going to fetch all the records), sort by the timestamp (descending for 
latest, ascending for oldest), and set the fetch limit to 1. If you want 
to use raw sql, click on the sql tab, which will show you the sql for 
your specific database.

HTH

Stefan Apelt wrote:

>Hi,
>
>sorry for the crosspost, I am not sure how many people are reading the
>eof-list.  My problem is as follows: I have a long list of records for
>user actions, simplified like this:
>
>  time      user             action
>
>  18:12    user foo         opened document
>  18:12    user bar         pasted paragraph
>  18:13    user foo         opened another document
>
>The  problem is that there are a lot of these entries in the database.
>Now  I  want  to specify a user and get only the latest entry for that
>user  (the one with the highest timestamp). The latest timestamp could
>also  be  some  time  in the past so I cannot compare with the current
>time.
>
>My  solution 'til now would be to fetch all records for the user, sort
>them  by  time and return the first (or last) element in the resulting
>array.  However,  since  there  can be literally thousands of records,
>this is going to be slow.
>
>Does  anyone  have  a better idea to produce SQL for only fetching the
>one record in question? I would be very grateful for that!
>
>  
>

-- 
Take care,
-Jon
============
Jonathan Frank
[email protected]
(C)757.675.5237
(O)202.616.0631 (direct)
============
Bluedog, Ltd.
www.bluedog.net
============