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 user_list and leave_record in order to fetch data from both table base on user_list table. Because without doing so, some user that has no leave record yet will not be shown.
Now when I run the following code, it says Unknown column 'a.id' in 'on clause'. But the column did exist in my table. I do appreciate it if someone can point me my mistake. Thank you in advance. :-)
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 <> '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 <> '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
btwice. Also, you are using old school join syntax. Try to avoid putting commas in theFROMclause.babut the result is still the same.. isn't the comma separating the table?.AS "name"or justAS namerather thanAS 'name'.Unknown column 'a.id' in 'on clause'