title: mysql left joining same table twice
body: <p>I'm trying to left join the same table twice but it's giving me some problems. I have two tables <code>ee_all</code> and <code>ee_calendar_events</code> that I want to join.</p>
  
  <pre><code>SELECT
      u.first_name,
      u.last_name,
      u.email,
      SUM(e1.total_vacation_hours_earned) AS vacation_hours_earned,
      SUM(e2.absent_hours)
  FROM ee_all AS u 
  LEFT JOIN ee_calendar_events AS e1 ON u.user_id = e1.sched_user_id
  LEFT JOIN ee_calendar_events AS e2 ON u.user_id = e2.sched_user_id AND e2.event_id = 2
  WHERE
      u.user_id = 23
  </code></pre>
  
  <p>The <code>vacation_hours_earned</code> column is supposed to return 133, which it does if I take out the second join. But soon as I add it, the query takes forever and the <code>vacation_hours_earned</code> has a value of 2000 or something (which is wrong). My guess is it's summing the row again when I add the second join, but I don't wan't that. I've been trying for a few hours but can't find a way around it, would appreciate any help.</p>