title: MySql Multiple Table query with left join
body: <p>Im asking this since I couldn't find the exact example of querying multiple table with left join and I am kind of new to using join. What I'm trying to do here is to join Table <code>user_list</code> and <code>leave_record</code> in order to fetch data from both table base on <code>user_list</code> table. Because without doing so, some user that has no leave record yet will not be shown.</p>
  
  <p>Now when I run the following code, it says <code>Unknown column 'a.id' in 'on clause'</code>. But the column did exist in my table. I do appreciate it if someone can point me my mistake. Thank you in advance. :-)</p>
  
  <pre><code>SELECT a.id,
         CONCAT(a.firstname, a.lastname) AS "name",
         a.date_joined,a.job_status,
         d.description,
         d.annual_cf AS 'allowed_cf',
         f.2016 AS "lastyear",
         g.2016 AS "last_annual_cf",
         h.2016 AS "ot_convert",
         f.2017 AS "current_ent",
         g.2017 AS "current_annual_cf",
         h.2017 AS "current_ot_convert",
        SUM(CASE WHEN b.start_date BETWEEN c.entitlement_start_date AND
                      c.entitlement_extention_date AND
                      b.submit_date BETWEEN c.entitlement_start_date AND
                      c.system_freez_start_date AND b.leave_type = '1' AND
                      b.s_status = 'Approved' AND b.status &lt;&gt; 'Canceled'
                 THEN b.no_days ELSE 0 END) a_annual
  FROM user_list a,
       leave_records b,
       system_settings c,
       job_category d, 
       annual_leave_ent f,
       annual_cf g,
       ot_convert h
  LEFT JOIN (SELECT id FROM leave_records) AS ba
      ON a.id = ba.id
  WHERE f.id = a.id AND a.enabled &lt;&gt; 'no' AND g.id = a.id AND h.id = a.id AND
        d.id = a.job_category AND a.company='14' AND
        c.year_id='2016'
  GROUP BY a.id
  ORDER BY a.id
  </code></pre>