gpt4 book ai didi

Mysql复制错误

转载 作者:行者123 更新时间:2023-11-28 23:27:25 25 4
gpt4 key购买 nike

为了在表(“projects”)中插入唯一的“project_title”值,我编写了如下查询。

INSERT INTO projects (projects.project_title, projects.description) 
SELECT * FROM (SELECT 'a title', 'a description') AS tmp
WHERE NOT EXISTS (SELECT projects.project_title FROM projects WHERE projects.project_title = 'a title') LIMIT 1

这工作正常,直到为项目标题和项目描述输入相同的条目并且查询将如下所示:

INSERT INTO projects (projects.project_title, projects.description) 
SELECT * FROM (SELECT 'text', 'text') AS tmp
WHERE NOT EXISTS (SELECT projects.project_title FROM projects WHERE projects.project_title = 'text') LIMIT 1

现在,我得到这个错误:

[Err] 1060 - Duplicate column name 'text'

如何摆脱这个重复错误?!

最佳答案

在此处提取错误语句:

SELECT 
tmp.*
FROM
(
SELECT 'text', 'text'
) AS tmp;

这个查询会产生这个错误

[Err] 1060 - Duplicate column name 'text'

因为您没有为列指定任何别名。

解决方案:

给列起别名:

SELECT 
tmp.*
FROM
(
SELECT
'text' AS firstText,
'text' AS secondText
) AS tmp;

关于Mysql复制错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38716474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com