gpt4 book ai didi

mysql - 使用 select 子句更新 mysql 作为更新值

转载 作者:行者123 更新时间:2023-11-29 13:02:30 25 4
gpt4 key购买 nike

我尝试将一个值从 t2.f2 复制到 t1.f1,即 PHPbb3 论坛的主题和帖子表。我尝试过以下sql:

UPDATE t_topics SET
topic_title = (SELECT t_posts.post_subject WHERE
t_posts.post_id = t_topics.topic_first_post_id)
WHERE topic_id = 2;

我遇到以下错误:

MySQL said:

`#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE t_posts.post_id = t_topics.topic_first_post_id) WHERE topic_id = 2' at line 1

如何使用 sql 实现此目的?

最佳答案

您缺少 from 子句:

UPDATE t_topics
SET topic_title = (SELECT t_posts.post_subject
FROM t_posts
WHERE t_posts.post_id = t_topics.topic_first_post_id
)
WHERE topic_id = 2;

关于mysql - 使用 select 子句更新 mysql 作为更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23146512/

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