简体   繁体   English

MySQL错误#1052 from子句中的列不明确

[英]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.

相关问题 完整性约束违规:1052 order order子句中的列'position'不明确(PHP,MySQL) - Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous (PHP, MySQL) Laravel 6 错误:SQLSTATE[23000]:违反完整性约束:1052 where 子句中的列“id_perusahaan”不明确 - Laravel 6 Error : SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id_perusahaan' in where clause is ambiguous Laravel SQL 错误:违反完整性约束:1052 where 子句中的列“id”不明确 - Laravel SQL Error: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 违反完整性约束:1052 order子句中的“位置”列不明确 - Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous 完整性约束违规:1052 where子句中的列'id'不明确 - Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous Laravel 完整性约束违规:1052 列 'id' in where 子句不明确 - Laravel Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 违反完整性约束:1052 where子句不明确的列'prof_id'Laravel - Integrity constraint violation: 1052 Column 'prof_id' in where clause is ambiguous Laravel Laravel Eloquent:违反完整性约束:where 子句中的 1052 列“id”不明确 - Laravel Eloquent: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 如何解决完整性约束违规:1052 列 'id' in where 子句在 laravel 中不明确 - How to solve Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous in laravel SQLSTATE [23000]:完整性约束违规:1052 order order中的'created_at'列不明确Laravel 5.5 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM