Hi,

I forgot to mention that the table contains more information, it has more columns than just a and b. These extra columns contains the actual
information that I'm looking for.


I.e. the mentioned table could be looking like this:

 +------+------+------+------+---------+---
 | a    | b    | data | user | comment | ...
 +------+------+------+------+---------+---

And I still want those entire rows with DISTINCT A and MAX(B).

Regards
Svein

I have this table where the columns and rows are organized like this:

+------+------+
| a    | b    |
+------+------+
|    1 |    1 |
|    2 |    1 |
|    2 |    2 |
|    2 |    3 |
|    2 |    4 |
|    3 |    1 |
|    3 |    2 |
+------+------+

I want to run a select that gives me one row for each unique value of
'a'. And in the cases where several rows exists for one single value of
'a', I require the rows with the largest values of 'b'. In SQL lingo that would be DISTINCT A and MAX(B), but I dont know how to write this into one select...


I.e. if I would apply these rules on the set above, I should get the
following result:

+------+------+
| a    | b    |
+------+------+
|    1 |    1 |
|    2 |    4 |
|    3 |    2 |
+------+------+

Does anyone know how to formalize this request into a single SELECT
statement (using mysql 4.0.13), please?



-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to