gpt4 book ai didi

mysql - SQL数据库: #1242 - Subquery returns more than 1 row

转载 作者:行者123 更新时间:2023-11-29 20:51:26 26 4
gpt4 key购买 nike

UPDATE table1 AS t1 
INNER JOIN table2 AS t2 ON t1.table1_id=t2.table2_id
SET t1.overview=t2.val
WHERE t1.table1_id=(SELECT table2_id
FROM table2
WHERE table2_id=1);

table2 有多个 id 值为 1,因此它给出

#1242 - Subquery returns more than 1 row

最佳答案

您需要一个DISTINCT

UPDATE table1 AS t1
INNER JOIN table2 AS t2
ON t1.table1_id = t2.table2_id
SET t1.overview = t2.val
WHERE t1.table1_id = (SELECT DISTINCT table2_id FROM table2 WHERE table2_id = 1);

如果table2_id是固定的,为什么不直接使用1,比如:

UPDATE table1 AS t1
INNER JOIN table2 AS t2
ON t1.table1_id = t2.table2_id
SET t1.overview = t2.val
WHERE t1.table1_id = 1;

关于mysql - SQL数据库: #1242 - Subquery returns more than 1 row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38012019/

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