在我的项目中,我有表 IDCA 和 IDCB。
我 cat 查询 sql 如下:
$liId=99;
select name from IDCA where stId='$liId';
结果是:
John
Stack
Shansa
Aliya
Stock
然后我用这些值设置 IDCB 的 allName。
update IDCB set allName=(select name from IDCA where stId='$liId') where stId='$liId';
但它工作失败。错误是:
ERROR 1242 (21000): Subquery returns more than 1 row
实际上,我想设置 allName='John,Stack,Shansa,Aliya,Stock'。那么谁可以帮助我呢?
最佳答案
尝试使用 GROUP_CONCAT()
update IDCB set allName=(
select GROUP_CONCAT(name)
from IDCA
where stId='$liId' GROUP BY stId)
where stId='$liId';
关于mysql - 如何设置来自其他选择的mysql更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46881366/