Re: How to get the latest record from the database
Jesse Barnum <[email protected]> Mon, 21 Jun 2004 16:57:16 -0400
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
Rather than hardcoding a LIMIT statement into your SQL, you could also set a fetchLimit of 1 in your fetch spec. This will only create a 1 EO, is very efficient on the EOF side, and has the benefit of avoiding manual SQL tweaking. Whether or not this is efficient on the database side depends on your JDBC driver - a good one will fetch the records in chunks, a less good one will pull all the matching records into memory. --Jesse Barnum, CEO, 360Works http://www.360works.com/ Try WooF, the only solution for linking WebObjects and FileMaker! On Jun 21, 2004, at 12:14 PM, 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! > > -- > Cheers, > Stefan > > > > > _______________________________________________ > EOF mailing list > [email protected] > http://www.omnigroup.com/mailman/listinfo/eof >