这可能是因为select
查询可能会为该列返回多个值value
UPDATE table_name
SET value = (SELECT max(value) FROM table_name WHERE key = "weather")
WHERE key = "colour";
或者
UPDATE table_name
SET value = (SELECT value FROM table_name WHERE key = "weather" limit 1)
WHERE key = "colour";
table_name
您可以尝试通过将子查询中的实例替换为(SELECT * FROM table_name)
:
UPDATE table_name
SET table_name.A =
(
SELECT B
FROM (SELECT * FROM table_name) AS something
INNER JOIN ...
)
另请检查如何从 MySQL 中的更新目标中进行选择
您不想在现实生活中只在子查询中使用 SELECT * FROM 表;我只是想让示例保持简单。实际上,您应该只在最里面的查询中选择您需要的列,并添加一个好的 WHERE 子句来限制结果。
编辑:-
正如您已经评论过的那样,但我已经在上面回答了使用这样的临时表:-
UPDATE table_name
SET value = (SELECT value FROM (SELECT value FROM table_name WHERE key="weather") AS x)
WHERE key="colour"