What aggregate functions work on a string, when using a GROUP BY?
I would usually GROUP BY user_id, but I am not sure what aggregate function can work over a string.
Goal is to get the currency for each user_id as one row:
user_id currency
12341235 "USD"
12341235 "USD"
12341235 "USD"
12341235 "USD"
05945949 "EURO"
05945949 "EURO"
05945949 "EURO"
99910277 "USD"
99910277 "USD"
99910277 "USD"
Finished data:
user_id currency
12341235 "USD"
05945949 "EURO"
99910277 "USD"
Demo
http://sqlfiddle.com/#!3/60ea7/5
A DISTINCT and GROUP BY usually generate the same query plan, so performance should be the same across both query constructs. GROUP BY should be used to apply aggregate operators to each group. If all you need is to remove duplicates then use DISTINCT. If you are using sub-queries execution plan for that query varies so in that case you need to check the execution plan before making decision of which is faster.