MySQL - 列已存在:1060 列名称“1”重复
MySQL - Column already exists: 1060 Duplicate column name '1'
我一直在尝试使用 唯一行 创建一个 INSERT
,但是,如果唯一行已经存在,它将简单地忽略插入和 return 没有错误。
为什么,and/or查询有什么问题?
INSERT INTO hashtag_mapping (user_id, cid, hashtag_id, date_created, date_modified)
SELECT * FROM (SELECT 1, 8923, 1, NOW(), CURRENT_TIMESTAMP) AS tmp
WHERE NOT EXISTS (
SELECT user_id, cid, hashtag_id
FROM hashtag_mapping
WHERE user_id = 1
AND cid = 8923
AND hashtag_id = 1
) LIMIT 1;
唯一键:unique_mapping (user_id, cid, hashtag_id), Unique
我从 MySQL 收到以下错误:
Column already exists: 1060 Duplicate column name '1'
table 设计如果有帮助...
id user_id cid hashtag_id date_created date_modified
------ ------- ---------- ---------- ------------------- ---------------------
1 1 8644 1 2016-03-23 15:19:54 2016-04-06 11:39:32
2 1 8644 2 2016-03-23 15:19:54 2016-04-06 11:39:34
3 1 8664 3 2016-03-25 17:02:32 2016-04-06 11:39:35
4 1 8664 4 2016-03-25 17:02:32 2016-04-06 11:39:36
您必须为列指定别名。如果您不这样做,MySQL 将使用常量作为名称。
SELECT 1 AS field1 , 8923 AS something , 1 AS field2, NOW(), CURRENT_TIMESTAMP
我一直在尝试使用 唯一行 创建一个 INSERT
,但是,如果唯一行已经存在,它将简单地忽略插入和 return 没有错误。
为什么,and/or查询有什么问题?
INSERT INTO hashtag_mapping (user_id, cid, hashtag_id, date_created, date_modified)
SELECT * FROM (SELECT 1, 8923, 1, NOW(), CURRENT_TIMESTAMP) AS tmp
WHERE NOT EXISTS (
SELECT user_id, cid, hashtag_id
FROM hashtag_mapping
WHERE user_id = 1
AND cid = 8923
AND hashtag_id = 1
) LIMIT 1;
唯一键:unique_mapping (user_id, cid, hashtag_id), Unique
我从 MySQL 收到以下错误:
Column already exists: 1060 Duplicate column name '1'
table 设计如果有帮助...
id user_id cid hashtag_id date_created date_modified
------ ------- ---------- ---------- ------------------- ---------------------
1 1 8644 1 2016-03-23 15:19:54 2016-04-06 11:39:32
2 1 8644 2 2016-03-23 15:19:54 2016-04-06 11:39:34
3 1 8664 3 2016-03-25 17:02:32 2016-04-06 11:39:35
4 1 8664 4 2016-03-25 17:02:32 2016-04-06 11:39:36
您必须为列指定别名。如果您不这样做,MySQL 将使用常量作为名称。
SELECT 1 AS field1 , 8923 AS something , 1 AS field2, NOW(), CURRENT_TIMESTAMP