[英]MySQL Error #1052 Column in from clause is ambiguous
Having some issues with a query to my MySQL DB: 查询我的MySQL数据库时遇到一些问题:
"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
. 当我对数据库运行此查询时,它返回错误#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. 我在此查询中还有其他LEFT JOIN
,出于可读性考虑,我刚刚删除了它们,并且可以很好地获取它们。 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. 该错误基本上意味着可以在查询的其他表中找到名称为area_id
的列。
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. 用table
名或别名替换table
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.