Bug #49173 | create view fails: MySQL error 1060 "duplicate column name" | ||
---|---|---|---|
Submitted: | 28 Nov 2009 3:26 | Modified: | 28 Nov 2009 13:38 |
Reporter: | David Sadler | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Errors | Severity: | S2 (Serious) |
Version: | 5.1.30-community | OS: | Windows (xp media center sp3) |
Assigned to: | CPU Architecture: | Any | |
Tags: | create view, duplicate column name, error 1060 |
[28 Nov 2009 3:26]
David Sadler
[28 Nov 2009 9:01]
Valeriy Kravchuk
When you create view, you create a virtual table. Table (and view, virtual table) can not have columns with the same name. Just add unique column alias to SELECT: SELECT ... c.name as name1, p.name as name2, ... Please, check if this solves the problem.
[28 Nov 2009 13:38]
David Sadler
Thanks, Valerily. Valeriy's advice to alias the duplicate names in the select clause solved the problem. I will search the doc to see if a switch can be thrown to automatically qualifiy the column names when the view is created. The switch would automatically add the table name (or letter) to the column name. Example: If the auto qualify column name preference is thrown, this select ... SELECT c.`name`, p.`name` FROM project p, company c where c.`id` = p.`company_id`; ... is treated by the view constructor as ... SELECT c.`name` as c_name, p.`name` as p_name FROM project p, company c where c.`id` = p.`company_id`;