title: PostgreSQL - GROUP BY clause or be used in an aggregate function confluence
body: <p>I'm trying to run some query which will bring an output of contact created per user, i get the below error when running the query, any ideas? </p>
  
  <p>Error:</p>
  
  <pre><code>ERROR:  column "user_mapping.lower_username" must appear in the GROUP BY clause or be used in an aggregate function
  </code></pre>
  
  <p>Query:</p>
  
  <pre><code>SELECT 
      lower_username AS "Username", 
      display_name AS "Full Name", 
      count(DISTINCT CONTENT.title) AS "Pages created"
  FROM 
      CONTENT
      LEFT JOIN 
      USER_MAPPING ON CONTENT.creator = USER_MAPPING.user_key
      LEFT JOIN 
      CWD_USER ON USER_MAPPING.lower_username = CWD_USER.lower_user_name
  WHERE 
      creator IS NOT NULL AND 
      CONTENTTYPE IN ('PAGE', 'BLOGPOST')
  GROUP BY creator
  ORDER BY "Pages created" DESC;
  </code></pre>