View Full Version : Not agregated column/ order before group by

06-13-2011, 05:42 AM
a b c d

1 2 beta 2
1 1 alpha 1
1 3 gama 3

select a,min(b), c
group by a

result --> 1 1 randome_c

How would I get , insted of randome_c, exactly 'alpha' based on fact that
column d has minimum at that record ? 'alpha' is just sample, it is realy randome string.

Old Pedant
06-13-2011, 06:03 AM
SELECT t.a, t.b, t.c, t.d
FROM table AS t, ( SELECT a, min(b) AS minb FROM table GROUP BY a ) AS x
WHERE t.a = x.a
AND t.b = x.minb

06-19-2011, 03:43 AM
How about that ? I guess more efficient, or mybe not.

SUBSTRING_INDEX(group_concat(c order by d),',',1)