$rs = mysql_query("
SELECT a.id
FROM a
JOIN b ON b.id=a.id
WHERE
b.p1=1 AND
a.p1=1");
while($r = mysql_fetch_assoc($rs))
$ids[] = $r['id'];
$rs = mysql_query("
UPDATE a
SET p2=2
WHERE id IN (".implode(",",$ids).")");
如何在一个查询中执行此操作?