Pentium10
Pentium10

Reputation: 207893

#1060 - Duplicate column name 'id'

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

Upvotes: 33

Views: 105090

Answers (4)

Pipo
Pipo

Reputation: 5073

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 ...

Upvotes: 0

Quassnoi
Quassnoi

Reputation: 425341

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?

Upvotes: 0

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 120937

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 

Upvotes: 13

Andomar
Andomar

Reputation: 238098

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

Upvotes: 45

Related Questions