Forum Moderators: open

Message Too Old, No Replies

displaying values with GROUP BY

         

sssweb

7:40 pm on Aug 12, 2006 (gmt 0)

10+ Year Member



When using 'GROUP BY' SQL on a column, how do I specify which value to display in other fields?

Example:

col1 = 1, 1, 1, 2, 2, 2
col2 = a, b, c, d, e, f

When I GROUP BY col1, I get:

col1 = 1, 2
col2 = c, f

but I want:

col2 = a, d
(i.e. the lowest value of col2 for each group)

FalseDawn

5:42 am on Aug 13, 2006 (gmt 0)

10+ Year Member



The MIN(column name) function should work.
eg
SELECT col1, MIN(col2) FROM table GROUP BY col1

sssweb

2:24 pm on Aug 13, 2006 (gmt 0)

10+ Year Member



Thanks -- that works.