title: SQL counting unique true values on join table
body: <p>I have a <code>users</code> table</p>
  
  <pre><code>Table "public.users"
  Column  |  Type   | Modifiers 
  --------+---------+-----------
  user_id | integer | 
  style   | boolean | 
  id      | integer | 
  </code></pre>
  
  <p>and an <code>access_rights</code> table</p>
  
  <pre><code>Table "public.access_rights"
  Column  |  Type   | Modifiers 
  --------+---------+-----------
  user_id | integer | 
  id      | integer | 
  </code></pre>
  
  <p>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. </p>
  
  <p>From this answer: <a href="https://stackoverflow.com/questions/5396498/postgresql-sql-count-of-true-values">postgresql - sql - count of `true` values</a>, I tried doing </p>
  
  <pre><code>SELECT COUNT( CASE WHEN style THEN 1 ELSE null END )
  from users
  join access_rights on access_rights.user_id = users.user_id
  ;
  </code></pre>
  
  <p>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?</p>