Bogdan Kanivets Bogdan Kanivets - 2 years ago 91
SQL Question

SQL query to select one of each kind

Let's say I have this table:

id colorName

1 red

2 blue

3 red

4 blue

How can I select one representative of each color?


1 red

2 blue

Answer Source

Not random representatives, but...

select color, min(id)
from   mytable
group by color;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download