我有一个表,我需要使用另一个表中的选择来更新它。
我的想法:
UPDATE articles,
(SELECT count(*) AS count FROM nots WHERE otherID=243 GROUP BY number) AS cnots
SET articles.first=(SELECT count FROM cnots WHERE number=1),
articles.second=(SELECT count FROM cnots WHERE number=2),
articles.third=(SELECT count FROM cnots WHERE number=3)
WHERE articles.ID=243
查询抛出错误“表'mydb.cnots'不存在”。
我可以用 3 个不同的选择来做到这一点,但我不想这样做,有什么想法吗?
最佳答案
(SELECT count(*) AS count FROM nots WHERE otherID=243 GROUP BY number) AS cnots
这里这一行应该就像有一个表一样。应该是这样的
(SELECT count(*) FROM cnots WHERE otherID=243 GROUP BY number) AS cnots
关于Mysql-从 select 中更新多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26827322/