I have a users
table
Table "public.users"
Column | Type | Modifiers
--------+---------+-----------
user_id | integer |
style | boolean |
id | integer |
and an access_rights
table
Table "public.access_rights"
Column | Type | Modifiers
--------+---------+-----------
user_id | integer |
id | integer |
I have a query joining users on access right and I want to count the number of values in the style column that are true.
From this answer: postgresql - sql - count of `true` values, I tried doing
SELECT COUNT( CASE WHEN style THEN 1 ELSE null END )
from users
join access_rights on access_rights.user_id = users.user_id
;
But that counts duplicate values when a user has multiple rows for access_rights. How can I count values only once when using a join?