您好我正在尝试在一个查询中组合UPDATE和SELECT语句。
这是我试过的那个。但没有工作。
$this->$db2->query('
UPDATE users
SET total = (total - (
SELECT floatingnumber
FROM posts
WHERE post_id = "'.$this->post_id.'"
LIMIT 1
))
WHERE id = "'.$this->post_user->id.'"
LIMIT 1
');
答案 0 :(得分:0)
使用INNER JOIN
尝试此项,而不使用SELECT
UPDATE users u
INNER JOIN posts p
ON // realationship between tables
SET total = total - p.floatingnumber
WHERE p.post_id = "'.$this->post_id.'"
AND u.id = "'.$this->post_user->id.'"
LIMIT 1