Re: How to get the latest record from the database

Anders Peterson <[email protected]> Mon, 21 Jun 2004 18:27:49 +0200
Newsgroups gmane.comp.web.webobjects.devel,gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
Define the fetch specification to do the sorting in SQL (as I believe 
you have) and to return the record you want first. Then set the fetch 
limit to 1 (under Options in EOModeler).

EOmodeler wont seem to use the limit-option (a bug) but it works when 
you run your application.

/Anders

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!