title: Select count of rows in another table in a Postgres SELECT statement
body: <p>I don't know quite how to phrase this so please help me with the title as well. :)</p>
  
  <p>I have two tables. Let's call them <code>A</code> and <code>B</code>. The <code>B</code> table has a <code>a_id</code> foreign key that points at <code>A.id</code>. Now I would like to write a <code>SELECT</code> statement that fetches all <code>A</code> records, with an additional column containing the count of <code>B</code> records per <code>A</code> row for each row in the result set.</p>
  
  <p>I'm using Postgresql 9 right now, but I guess this would be a generic SQL question?</p>
  
  <p>EDIT:</p>
  
  <p>In the end I went for trigger-cache solution, where <code>A.b_count</code> is updated via a function each time <code>B</code> changes.</p>