title: SQL Join issue returning NULL values
body: <p>I am having trouble running a query over three tables:</p>
  
  <p>users, user_teams, user_messages</p>
  
  <p>I wish to create a report where a line manager can see the total for incoming mail and outgoing mail for all members of their team.  The query is to show zero values for a user if there are no outgoing or incoming.</p>
  
  <p>My tables are as follows:</p>
  
  <pre><code>users
  ------
  uid
  forename
  surname
  
  user_teams
  -------------
  id
  manager_id
  member_id
  
  user_messages
  -------------
  id
  outgoing
  incoming
  uid
  msg_date
  </code></pre>
  
  <p>Both manager_id and member_id relate to the uid field of users.  There is a one to many relationship between managers and users.</p>
  
  <p>My query so far is this:</p>
  
  <pre><code>SELECT u.uid, u.forename, u.surname,
  SUM(IF(m.outgoing=0 ,1,0)) AS total_outgoing,
  SUM(IF(m.incoming&gt;0 ,1,0)) AS total_incoming,
  FROM users u
  INNER JOIN user_messages m
  ON m.uid=u.uid AND m.msg_date&gt;='2012-09-01' AND m.msg_date&lt;='2013-08-31'
  RIGHT JOIN user_teams ut ON ut.member_id=u.uid
  WHERE ut.leader_id=?
  GROUP BY u.uid
  ORDER BY u.surname ASC 
  </code></pre>
  
  <p>This functions correctly if a user has either sent or received a message.  However, if the SUM for both fields is zero, I recieve NULL for uid, forename and surname.</p>