使用子查询更新表
正如你所看到的,我想要做的是:
[1] 获取与表 forum_qa 中的 $toggled
匹配的记录的 author_id
[2 ] 更新 user_profiles 中的 reputation,其中 user_id 与 author_id 匹配,
UPDATE user_profiles
(SELECT forum_qa_author_id AS author_id
FROM forum_qa
WHERE forum_qa_id = $toggled) AS f
SET user_profiles.reputation = user_profiles.reputation - 15
WHERE user_profiles.user_id = f.author_id
这给了我一个 1064 语法错误(SELECT...
。
知道我在这里做错了什么吗?
感谢您的帮助!
As you can see what I want to do is:
[1] grab the author_id of a record that matches $toggled
in table forum_qa
[2] update reputation in user_profiles where user_id matches author_id
UPDATE user_profiles
(SELECT forum_qa_author_id AS author_id
FROM forum_qa
WHERE forum_qa_id = $toggled) AS f
SET user_profiles.reputation = user_profiles.reputation - 15
WHERE user_profiles.user_id = f.author_id
This is giving me a 1064 syntax error at (SELECT...
.
Any idea what I'm doing wrong here?
Thanks for helping!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
Try:
我刚刚意识到你正在使用MySQL。这是针对 MS SQL 的,我不确定你是否可以在 MySQL 中以完全相同的方式使用它,但希望它能有一点帮助。
I just realised that you are using MySQL. This is for MS SQL, I'm not sure if you can use it exactly the same way in MySQL but hopefully it's a little bit of help..
子查询必须位于“SET”之后。在这种情况下,它可能不一定需要子查询...
尝试...
The subquery has to come after the "SET" . In this case it might not necessarily need a sub query...
try...