MySQL Forums
Forum List  »  Newbie

Re: GROUP BY, MIN() row ordering problems!
Posted by: Max Waterman
Date: January 28, 2008 01:30AM

Gavin Lovegrove Wrote:
-------------------------------------------------------
> Thanks Max for your reply.
>
> That was similar to what I was getting. Although
> the results showed unique athleteID they were in
> the wrong order still.

What order are they supposed to be in?

You only have 4 athletes, so you only want 4 rows in your output, right? The order you have on your web page seems to be 'r.time ASC'. Isn't this correct?
SELECT *, MIN(r.time) FROM results AS r JOIN athletes AS a USING (athleteID) GROUP BY athleteID ORDER BY r.time ASC;
+-----------+----------+-------+----------+----------+------------+--------+------+---------+-------------+--------+-------------+------------+-----------+-----------+--------+------------+--------+-------------+
| athleteID | resultID | event | ageGroup | time     | distHeight | record | wind | placing | competition | in_out | venue       | date       | nameFirst | nameLast  | gender | DOB        | clubID | MIN(r.time) |
+-----------+----------+-------+----------+----------+------------+--------+------+---------+-------------+--------+-------------+------------+-----------+-----------+--------+------------+--------+-------------+
|      3450 |       28 | 100m  | SM       | 00010.20 | 000000     |        | 1.3  | 1       | Test Meet   | Out    | Inglewood   | 2008-02-02 | Gavin     | LOVEGROVE | M      | 1967-10-21 |    151 | 00010.15    | 
|       822 |       20 | 100m  | SM       | 00010.46 | 000000     |        | 1.7  | 3       | RESI        | Out    | Sydney      | 2008-01-02 | James     | DOLPHIN   | M      | 1983-06-17 |    151 | 00010.20    | 
|       825 |       22 | 100m  | SM       | 00010.58 | 000000     |        | 1.6  | 1       | Centre      | Out    | Dunedin     | 2008-01-02 | Chris     | DONALDSON | M      | 1975-05-26 |    151 | 00010.56    | 
|       199 |       23 | 100m  | SM       | 00010.59 | 000000     |        | 0.9  | 2       | Battle      | Out    | North Shore | 2008-01-02 | Craig     | BEARDA    | M      | 1982-06-17 |    151 | 00010.59    | 
+-----------+----------+-------+----------+----------+------------+--------+------+---------+-------------+--------+-------------+------------+-----------+-----------+--------+------------+--------+-------------+
Max.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.