简体   繁体   中英

getting mysql error 1054

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.

Simply, the "mobile" column from the table transactions does not exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM