【MySQL】Subquery returns more than 1 row 解决方案

问题提出:

    有如下需求,在同一张表中,当某个字段的值符合一定条件时,修改另一个字段的值。

    SQL:update topic set topi_closed = 1 where topi_id = (select topi_id from (select * from topic) as b where now() > topi_stilltime and topi_closed = 0)

运行结果:

    当有多个符合查询条件时会报如下错误:Subquery returns more than 1 row (子查询返回多行1)

解决方案:添加any方法,如下

     SQL:update topic set topi_closed = 1 where topi_id = any(select topi_id from (select * from topic) as b where now() > topi_stilltime and topi_closed = 0)


MySQL的子查询:all、any、some

详情链接:http://blog.csdn.net/c517984604/article/details/7052186

你可能感兴趣的:(数据库)