Skip to content
Advertisement

get only unique record before grouping

I have this table named votes, this table might consist of duplicate records with these columns business_id and user_id. I created a view that will display the count of votes per business but unfortunately the duplicates also has been counted which should not be. Below is my view code

The actual data would be

so the result should be

so it should be user_id must have unique business_id and business_id must have unique user_id

tried adding another GROUP BY but seems an error.

Advertisement

Answer

If you want to count each user_id just once per business_id, you can use count(distinct ...):


Edit: from your sample data, it looks like you want:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement