title: PostgreSQL: left outer join syntax
body: <p>I'm using PostgreSQL 8.4.6 with CentOS 5.5 and have a table of users:</p>
  
  <pre><code># select * from pref_users where id='DE2';
   id  | first_name | last_name | female |      avatar      |        city         | lat | lng |           login            | last_ip | medals |           logout
  -----+------------+-----------+--------+------------------+---------------------+-----+-----+----------------------------+---------+--------+----------------------------
   DE2 | Alex       |           | f      | 2_1280837766.jpg | г. Бохум в Германии |     |     | 2011-01-02 19:26:37.790909 |         |        | 2011-01-02 19:29:30.197062
  (1 row)
  </code></pre>
  
  <p>and another table listing their "virtual money" won in a game each week:</p>
  
  <pre><code># select * from pref_money where id='DE2';
   id  | money |   yw
  -----+-------+---------
   DE2 |    66 | 2010-48
  (1 row)
  </code></pre>
  
  <p>Then I'm trying to display both of these infos for a user, but I'm only interested in the user's money for the current week:</p>
  
  <pre><code># select u.id,
      u.first_name,
      u.city,
      u.avatar,
      m.money,
      u.login &gt; u.logout as online
  from pref_users u, pref_money m where
      m.yw=to_char(current_timestamp, 'YYYY-IW') and
      u.id=m.id and
      u.id='DE2'
  order by m.money desc;
   id | first_name | city | avatar | money | online
  ----+------------+------+--------+-------+--------
  (0 rows)
  </code></pre>
  
  <p>In this case I've got no rows, because the user 'DE2' hasn't earned any "virtual money" this week yet.</p>
  
  <p>I'd like to change my query so that it <strong>always returns data for existing users</strong> and if they haven't played this week - then the query should return 0. </p>
  
  <p>So I guess I need an <a href="http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html" rel="nofollow">outer left join</a> and I'm trying:</p>
  
  <pre><code> select u.id,
      u.first_name,
      u.city,
      u.avatar,
      m.money,
      u.login &gt; u.logout as online
  from pref_users u left outer join pref_money m on (
      m.yw=to_char(current_timestamp, 'YYYY-IW') and
      u.id=m.id and
      u.id='DE2')
  order by m.money desc;
  </code></pre>
  
  <p>but these returns me a lot of rows with different users instead of just one with the id='DE2'.</p>
  
  <p>What am I doing wrong please?</p>