gpt4 book ai didi

mysql - 如果子表的记录字段有值,如何更新字段?

转载 作者:行者123 更新时间:2023-11-30 00:39:22 24 4
gpt4 key购买 nike

如果表 2 的字段之一和与表 1 相同的 idA 有一些 did=yes,我想更新表 1,字段 did 为 yes,否则 did=false。

我已经完成了一个触发器来更新新的更新,但现在我必须更新表中已有的所有旧记录。

表 1

idA b  done
--------------
1 a
2 b
3 c

表 2

idB idA done
--------------
1 1 yes
2 1 no
3 1 yes
4 2 no
5 2 no
6 3 no
7 3 yes

http://sqlfiddle.com/#!2/8ee5f3/5

最佳答案

试试这个:

UPDATE table1 JOIN table2
ON table1.idA = table2.idA
AND table2.done = yes
SET table1.done = yes

工作演示:http://sqlfiddle.com/#!2/6066f/1

关于mysql - 如果子表的记录字段有值,如何更新字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21901751/

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