Regarding the Column '' in field list is ambiguous error in MySQL. Its caused if mysql cant figure what table the field name belongs to. Does anyone know a different approach to specifying the qualified table name for fields, other than prefixing the table name to the field itself. Say I have a list of fields like so
INSERT INTO dupes
( lead_id,set_id,upload_date,agent,callcenter
,generation_date,vendors,first_name
,last_name,email,phone,address,city,state,zip,dob
,gender,marital_status,rented,year,make,model,trim
,vin,primary_use,miles_oneway,mileage,license_num,license_state
,education,job_title,license_status)
(SELECT lead_id,set_id,upload_date,agent,vendors,callcenter
,generation_date,first_name,last_name
,email,phone,address,city,state,zip,dob,gender,marital_status
,rented,year,make,model,trim,vin,primary_use,miles_oneway
,mileage,license_num,license_state,education,job_title
,license_status
FROM leads_auto
JOIN (
SELECT vendors, email, MIN(lead_id) min_lead_id
FROM leads_auto
WHERE vendors = 1762
GROUP BY vendors, email) y
ON y.vendors = leads_auto.vendors
AND y.email = leads_auto.email
AND leads_auto.lead_id <> y.min_lead_id)
Now I was thinking of using GROUP_CONCAT([fields] SEPARATOR ',[table name].') to prefix the fields into a variable and then execute it. Does anyone else have any ideas?
I can see right away that the field ’email’ is ambiguous, because it exists in your first table leads_auto, and you’re selecting it in your JOIN. When you are using JOIN, you should prefix all of your SELECTions with an explicit table alias, like so:
This way you can reference
la.field_nameory.field_nameand be explicit in which one you mean.