0

I have the following table named stuff:

Serial  Color
1       Red 
2       Red
3       Green
4       Blue
5       Green
6       Green
7       Orange

I run a simple select query:

SELECT * FROM stuff ORDER BY Serial

This simply returns all entries ordered by the Serial. But what I actually need, is for the query to only return the first unique occurrence of each Color while maintaining the same order.

The result set I need returned:

1       Red 
3       Green
4       Blue
7       Orange
Askerman
  • 787
  • 1
  • 12
  • 31

1 Answers1

0

Group by the colors and take the lowest serial for each group. You can also order by that

select min(serial), color
from your_table
group by color
order by min(serial)
juergen d
  • 201,996
  • 37
  • 293
  • 362