title: PostgreSQL LEFT JOIN not working properly
body: <p>I have 2 tables:</p>
  
  <pre><code>T1 (id, flag1)
  T2 (id, amount, date, flag2, t1_id);
  </code></pre>
  
  <p>I have the following query:</p>
  
  <pre><code>SELECT T1.id, ROUND(COALESCE(SUM(T2.amount), 0), 2) AS spent_amount
  FROM T1
  LEFT JOIN T2 ON T2.t1_id = T1.id
  WHERE T2.date &lt;= '2014-01-01' AND T2.flag2 = 't' AND T1.flag1 = 't'
  GROUP BY T1.id
  </code></pre>
  
  <p>The problem is that I want to have a row in the result such as: <code>id = 123, spent_amount = 0</code> in case where I have an entrance in <code>T1</code>, but it has no connected rows in <code>T2</code>.</p>