0

我有以下 MySQL 语句:

UPDATE xxx_iop_user_plans
SET state = 1, accepted = 1
WHERE id IN (SELECT iup1.id FROM xxx_iop_user_plans iup1
INNER JOIN xxx_iop_user_ed iue ON iup1.user_id = iue.user_id
WHERE iue.parent_id = 44 AND iup1.iop_id = 11)

我应该如何更新此语句以更新具有从SELECT语句返回的列表中存在的 ID 号的行?

4

2 回答 2

1

我本来希望你的更新声明能做到这一点。如果它没有更新所有这些 ID,它在做什么?您可以重新组织查询以将 select 子查询放在 from 子句中:

UPDATE x 
SET state = 1, accepted = 1
FROM xxx_iop_user_plans x 
    INNER JOIN (
        SELECT iup1.id 
        FROM xxx_iop_user_plans iup1
            INNER JOIN xxx_iop_user_ed iue ON iup1.user_id = iue.user_id
        WHERE iue.parent_id = 44 AND iup1.iop_id = 11
    ) y ON x.ID = y.ID

但我不希望这与您已有的行为有任何不同。还是试试看吧。

于 2013-09-24T23:34:49.547 回答
0

您应该使用 MySQL多表更新语法,如下所示:

UPDATE xxx_iop_user_plans
  INNER JOIN xxx_iop_user_ed ON xxx_iop_user_plans.user_id = xxx_iop_user_ed.user_id
SET state = 1, accepted = 1
WHERE xxx_iop_user_ed.parent_id = 44 
  AND xxx_iop_user_plans.iop_id = 11;
于 2013-09-24T23:39:05.207 回答