0

您好,我正在尝试在一个查询中结合 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
');
4

1 回答 1

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
于 2013-01-03T17:33:42.883 回答