验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

MySQL错误代码1052 Column 'xxx' in field list is ambiguous如何解决

阅读:977 来源:乙速云 作者:代码code

MySQL错误代码1052 Column 'xxx' in field list is ambiguous如何解决

错误代码: 1052 Column ‘xxx’ in field list is ambiguous出现的原因和解决方法

一、 例子

查询员工编号 employee_id 和其对应的部门名称 department_name

SELECT employee_id, department_name, department_id
FROM employees, departments
WHERE employees.`department_id` = departments.`department_id`;

查询结果出现以下错误:

错误代码: 1052 Column 'department_id' in field list is ambiguous

二、 错误原因

第 1 行代码中“部门编号” department_id 没有指明是 2 个表中的哪一个表。因为在员工表 employees 中和部门表 departments 中都存在同名的字段“部门编号” department_id 。因此需要指明第 1 行代码中“部门编号” department_id 是来自哪个表。

三、 正确写法

SELECT employee_id, department_name, employees.department_id
FROM employees, departments
WHERE employees.`department_id` = departments.`department_id`;

把第 1 行代码中的 department_id 改成 employees.department_id ,说明字段“部门编号” department_id 是来自员工表 employees 中的。

查询结果:

MySQL错误代码1052 Column 'xxx' in field list is ambiguous如何解决

分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>