title: PostgreSQL - GROUP BY clause
body: <p>I want to search by tags, and then list all articles with that tag, and also how many of given tags they match. So for example I might have:</p>
  
  <pre><code> Page1 - 2 (has css and php tag)
   Page2 - 1 (has only css tag)
  </code></pre>
  
  <p>Query:</p>
  
  <pre><code>SELECT COUNT(t.tag)
  FROM a_tags t
  JOIN w_articles2tag a2t ON a2t.tag = t.id 
  JOIN w_article a ON a.id = a2t.article 
  WHERE t.tag = 'css' OR t.tag = 'php'
  GROUP BY t.tag
  LIMIT 9
  </code></pre>
  
  <p>When I only put <code>COUNT(t.tag)</code> the query works, and I get okay results. But if I append e.g. <code>ID</code> of my article I get following error:</p>
  
  <blockquote>
    <p>ERROR:  column "a.title" must appear in the GROUP BY clause or be used in an aggregate function
       LINE 1: SELECT COUNT(t.tag), a.title FROM a_tags t</p>
  </blockquote>
  
  <p>How to add said columns to this query?</p>