#1060 - Duplicate column name 'id'

百般思念 提交于 2019-11-26 23:13:00

问题


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

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

回答1:


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




回答2:


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:

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 



回答3:


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 JOIN instead?




回答4:


Had the same problem, renaming into select clause saved me

SELECT people.id, vehicle.id ...

I renamed it with AS keyword

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


来源:https://stackoverflow.com/questions/4815627/1060-duplicate-column-name-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!