Hola Rodrigo,

I suggest that you use a temporary table:

CREATE tmp (
    INT id,
    TIME max);

INSERT INTO tmp
SELECT mytable.id, MAX(mytable.start)
FROM mytable
GROUP BY mytable.id;

and then join it to your original table:

SELECT M.*
FROM mytable M, tmp T
WHERE M.id=T.id
AND M.start=T.max;

I didn't try it, but that's what I would try.

Un saludo,

Olivier

----- Original Message -----
From: Rodrigo Gonzalez <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 30, 2001 4:56 PM
Subject: GROUPING


Hi,

I have to do a query but i don't know how to do this...

I have this table

id int
start time
stop time
...
There are 2 to 4 rows for each id

I have to select one row for each id where start is the max value between
all rows with this id

If you have an idea please let me know

Thanks



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to