I’m trying to create a new MySQL from a SELECT statement:
CREATE TABLE site_database AS(SELECT database_id, name, description, site_id FROM sitematrix_databases INNER JOIN site
matrix_site_databases ON sitematrix_site_databases.database_id = sitematrix_data
bases.database_id);
When I execute the SELECT statement, I get:
+-------------+--------+-------------+-------------+---------+
| database_id | name | description | database_id | site_id |
+-------------+--------+-------------+-------------+---------+
| 5 | tc2007 | | 5 | 1 |
| 5 | tc2007 | | 5 | 8 |
| 5 | tc2007 | | 5 | 9 |
| 5 | tc2007 | | 5 | 12 |
| 5 | tc2007 | | 5 | 14 |
+-------------+--------+-------------+-------------+---------+
However, when I try to create the table, I get:
ERROR 1052 (23000): Column 'database_id' in field list is ambiguous
How can I solve this problem?
In your select statement make sure you specify which table the database id comes from:
Would work, mysql requires this when more than one table have the same field names.
You could simplify it as thus: