db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Allen <...@mojavelinux.com>
Subject Re: getting id of MAX entry (try ORDER BY)
Date Wed, 26 Mar 2003 00:03:01 GMT

Peter S. Hamlen (phamlen@mail.com) wrote:

> If you're really interested in the eventid with the max date, then there
> is a simple SQL trick to solve it:
> 
> select eventid from event order by event_date desc;
> 
> Then grab the first eventid - that's your max.   If your problem was
> trickier - say you wanted the event id of the max date before Jan 15,
> 2003, then it would be:
> 
> select eventid from event where eventdate < '01/16/2003' order by
> event_date desc;
> 
> This kind of trick (taking only the first record returned and using
> ORDER BY to make sure you get the max or min) is useful in lots of
> places.
> 
> -Peter

Your point is well taken and definitely something I considered, but
my issue is with speed.  If I select everything then it would seem
much slower than actually doing a query on one record (especially in
torque since it spends time populating Java objects with the
results).  I have stayed away from Limit clauses since they are
non-ansi SQL.  I am very curious to know how one accomplishes
efficiency with SQL without Limit statements.

dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <dan@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
'One Microsoft Way' is more than just an address.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Mime
View raw message