简体   繁体   中英

MySQL Error #1052 Column in from clause is ambiguous

Having some issues with a query to my MySQL DB:

"SELECT event_id, area_name FROM tie_in.events LEFT JOIN tie_in.area USING (area_id)"

When I run this query against my DB it returns the error #1052 - Column 'area_id' in from clause is ambiguous .

I have other LEFT JOIN s in this query I just removed them for readability and they fetch fine. Any help to resolve this would be greatly appreciated.

Thanks guys!

If multiple tables have columns with the same name then you have to tell the DB which one to take by adding the table name in front of it

SELECT e.event_id, 
       a.area_name 
FROM tie_in.events e
LEFT JOIN tie_in.area a ON a.area_id = e.area_id 

The error basically means that a column with the name area_id can be found in other tables in your query.

You can alias the column name with a prefix:

"SELECT event_id, area_name FROM tie_in.events LEFT JOIN tie_in.area USING (table.area_id)"

Replace table with the table name or alias.

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