MySQL #1060 - 重复的列名“id”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4815627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:32:21  来源:igfitidea点击:

#1060 - Duplicate column name 'id'

mysqlsqlmysql-error-1060

提问by Pentium10

Why I get #1060 - Duplicate column name 'id'

为什么我得到 #1060 - 重复的列名“id”

SELECT COUNT(*) FROM (SELECT * FROM `tips` `t` LEFT JOIN
tip_usage ON tip_usage.tip_id=t.id GROUP BY t.id) sq

回答by Andomar

Probably because the * in select *selects two columns with the same name from tip_usageand tips.

可能是因为 * inselect *tip_usage和中选择了具有相同名称的两列tips

回答by Klaus Byskov Pedersen

Probably it's because the inner select yields two columns with the name id. Since you are not using those columns, you can just change the select to:

可能是因为内部选择产生两列名称为id。由于您没有使用这些列,您只需将选择更改为:

SELECT COUNT(*) FROM (SELECT t.id FROM `tips` `t` 
LEFT JOIN tip_usage ON tip_usage.tip_id=t.id 
GROUP BY t.id) sq 

回答by Quassnoi

Your query is equivalent to this:

您的查询相当于:

SELECT  COUNT(DISTINCT id)
FROM    tips

, there is no need in a join.

,不需要加入。

Are you sure you didn't want an INNER JOINinstead?

你确定你不想要一个INNER JOIN吗?

回答by Pipo

Had the same problem, renaming into select clause saved me

有同样的问题,重命名为 select 子句拯救了我

SELECT people.id, vehicle.id ...

I renamed it with ASkeyword

我用AS关键字将其重命名

SELECT people.id AS person_id, vehicle.id ...