mysql-error-1060

Duplicate column names in SQL query

烂漫一生 提交于 2020-01-03 19:01:44
问题 How do I avoid a dup column name error in MySQL when creating a VIEW on two tables that both have the same column name as shown here CREATE VIEW db.VI_RegionCity AS SELECT Region.Name, City.Name FROM db.Region Region, db.City City WHERE Region.RegionCode = City.RegionCode ERROR: Duplicate column name 'Name' 回答1: Using alias for column name CREATE VIEW db.VI_RegionCity AS SELECT Region.Name as Region_name, City.Name as City_name ...//rest of the query 回答2: CREATE VIEW db.VI_RegionCity AS

Duplicate column names in SQL query

让人想犯罪 __ 提交于 2020-01-03 19:01:10
问题 How do I avoid a dup column name error in MySQL when creating a VIEW on two tables that both have the same column name as shown here CREATE VIEW db.VI_RegionCity AS SELECT Region.Name, City.Name FROM db.Region Region, db.City City WHERE Region.RegionCode = City.RegionCode ERROR: Duplicate column name 'Name' 回答1: Using alias for column name CREATE VIEW db.VI_RegionCity AS SELECT Region.Name as Region_name, City.Name as City_name ...//rest of the query 回答2: CREATE VIEW db.VI_RegionCity AS

Alter ignore table add column if not exists using the SQL statement

耗尽温柔 提交于 2019-12-07 09:08:47
问题 i want to add a new column to a mysql table, but i want to ignore the adding of column, if the column already exists i am currently using ALTER IGNORE TABLE `db`.`tablename` ADD COLUMN `column_name` text NULL; but this is throwing an error saying : "ERROR 1060 (42S21): Duplicate column name 'column_name'" even though i am using the IGNORE, this is not working i want this to work using the normal SQL statement, instead of a stored procedure 回答1: According to the documentation: IGNORE is a

Alter ignore table add column if not exists using the SQL statement

天涯浪子 提交于 2019-12-05 13:36:16
i want to add a new column to a mysql table, but i want to ignore the adding of column, if the column already exists i am currently using ALTER IGNORE TABLE `db`.`tablename` ADD COLUMN `column_name` text NULL; but this is throwing an error saying : "ERROR 1060 (42S21): Duplicate column name 'column_name'" even though i am using the IGNORE, this is not working i want this to work using the normal SQL statement, instead of a stored procedure According to the documentation : IGNORE is a MySQL extension to standard SQL. It controls how ALTER TABLE works if there are duplicates on unique keys in

Duplicate column on join

核能气质少年 提交于 2019-12-02 01:10:00
问题 I'm trying to join three tables, after filtering one down to the most recent entry per user. However, all of a sudden I'm running into the error Duplicate column name 'username' . I need to join on this "duplicate" column. How do I fix this? SELECT customers.id,customers.name,customers.username,customers.phone,customers.email,radcheck.value as password FROM customers RIGHT JOIN radcheck ON customers.username = radcheck.username LEFT JOIN ( SELECT * FROM radacct INNER JOIN ( SELECT username

MySQL Error 1060: Duplicate column name ALTER TABLE

烈酒焚心 提交于 2019-12-01 13:57:58
I am having some problems with a query because of errors in the code that I did not create. $query = $this->db->query("ALTER TABLE `" . DB_PREFIX . "customer` ADD `customer_type` TINYINT(1) NOT NULL; I'm not a coder, but have so far fixed (I think) the error. By comparing with other queries that don't throw errors and reading quite a few similar posts on stackoverflow, I added a missing quote, a parenthese, and semi-colon. No more error, but not sure if this is even the correct way of doing it? I ended up with this: $query = $this->db->query("ALTER TABLE `" . DB_PREFIX . "customer` ADD

MySQL Error 1060: Duplicate column name ALTER TABLE

ぃ、小莉子 提交于 2019-12-01 10:56:38
问题 I am having some problems with a query because of errors in the code that I did not create. $query = $this->db->query("ALTER TABLE `" . DB_PREFIX . "customer` ADD `customer_type` TINYINT(1) NOT NULL; I'm not a coder, but have so far fixed (I think) the error. By comparing with other queries that don't throw errors and reading quite a few similar posts on stackoverflow, I added a missing quote, a parenthese, and semi-colon. No more error, but not sure if this is even the correct way of doing

#1060 - Duplicate column name 'id'

江枫思渺然 提交于 2019-11-27 22:46:19
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 Probably because the * in select * selects two columns with the same name from tip_usage and tips . 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 Your query is equivalent to this: SELECT COUNT(DISTINCT id) FROM tips , there is

#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