MYSQL更新记录取决于子查询的where条件

时间:2013-06-17 23:53:25

标签: mysql sql-update subquery

我得到子查询返回多行的错误。如何解决这个问题:

UPDATE sales
    SET newsletter='0'
    WHERE (user_id='33' AND product_id=(SELECT product_id FROM phplist_list WHERE id = (SELECT listid FROM phplist_listmessage WHERE messageid='20')))

1 个答案:

答案 0 :(得分:2)

您可以使用in代替=来解决此问题:

UPDATE sales
    SET newsletter='0'
    WHERE user_id = '33' AND
          product_id in (SELECT product_id
                         FROM phplist_list
                         WHERE id in (SELECT listid
                                      FROM phplist_listmessage
                                      WHERE messageid = '20'
                                     )
                        )