[英]UPDATE column using a result from SELECT subquery
This query returns an error : "Subquery returns more than one row": 该查询返回错误:“子查询返回多个行”:
UPDATE forums as f
SET f.f_last_pid = (SELECT pid FROM posts ORDER BY ptime DESC )
I know that i need to use ANY
before the subquery but that won't get the proper result I want. 我知道我需要在子查询之前使用
ANY
,但是那不会得到我想要的正确结果。 I want to update every row in my forums table based on the result shown from the subquery. 我想根据子查询显示的结果更新论坛表中的每一行。
UPDATE forums as f
SET f.f_last_pid =
(SELECT pid FROM posts ORDER BY ptime DESC LIMIT 1 )
But (without really knowing your schema), you're not joining these tables on anything. 但是(实际上并不了解您的架构),您并没有将这些表加入任何对象。 Every
last_pid
in forums
would be updated by the last post in posts
每
last_pid
在forums
会在帖子的最后更新posts
UPDATE forums as f
SET f.f_last_pid = (SELECT pid FROM posts ORDER BY ptime DESC LIMIT 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.