I am getting this error: #1054 - Unknown column 't.mobile' in 'on clause'
SELECT t.*,v.name,v.contact_person_email,l.firstname as memname
FROM transactions t , vendor v
LEFT JOIN loyalty_members l ON (t.mobile=l.mobile)
WHERE t.vendor_id ='N1WU95'
AND v.alert_mail = '2'
AND t.add_date <= '2011-07-22 09:00:00'
AND t.add_date >= '2011-07-21 09:00:00'
AND t.vendor_id = v.id
AND t.type = '1'
AND t.deleted != '1'
AND t.reference_id = '0'
GROUP BY t.mobile
HAVING COUNT(t.mobile) > 1;
Can anyone please help me to solve this out?
Thanks.
Try:
SELECT t.*, v.name, v.contact_person_email, l.firstname memname
FROM vendor v, transactions t
LEFT JOIN loyalty_members l ON t.mobile = l.mobile
WHERE t.vendor_id ='N1WU95'
AND v.alert_mail = '2'
AND t.add_date <= '2011-07-22 09:00:00'
AND t.add_date >= '2011-07-21 09:00:00'
AND t.vendor_id = v.id
AND t.type = '1'
AND t.deleted != '1'
AND t.reference_id = '0'
GROUP BY t.mobile
HAVING COUNT(t.mobile) > 1;
You were doing a LEFT JOIN
with the wrong table sequence. The engine was trying to join vendor
table with loyalty_members
table.