title: HAVING clause in PostgreSQL
body: <p>I'm rewriting the MySQL queries to PostgreSQL. I have table with articles and another table with categories. I need to select all categories, which has at least 1 article:</p>
  
  <pre><code>SELECT c.*,(
      SELECT COUNT(*) 
      FROM articles a 
      WHERE a."active"=TRUE AND a."category_id"=c."id") "count_articles" 
  FROM articles_categories c 
  HAVING (
      SELECT COUNT(*) 
      FROM articles a 
      WHERE a."active"=TRUE AND a."category_id"=c."id" ) &gt; 0
  </code></pre>
  
  <p>I don't know why, but this query is causing an error:</p>
  
  <pre><code>ERROR:  column "c.id" must appear in the GROUP BY clause or be used in an aggregate function at character 8
  </code></pre>