Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#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
like image 776
Pentium10 Avatar asked Jan 27 '11 11:01

Pentium10


2 Answers

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

like image 160
Andomar Avatar answered Oct 02 '22 11:10

Andomar


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 
like image 39
Klaus Byskov Pedersen Avatar answered Oct 01 '22 11:10

Klaus Byskov Pedersen