Assuming the following table:
USER COLOR ORDER
==================
JOE RED 1
JOE BLUE 2
PHIL BLUE 3
Joe first chose red, then chose blue as his favorite color… How do you write a query that returns:
COLOR COUNT
RED 1
BLUE 1
Where only Joe’s first vote is counted?
You would get the lowest ORDER value for each USER, and then join that against the table again to get the COLOR for those records, then group by the COLOR to count them: