解决MySQL不能更新同一张表查出来的数据问题

 

MYSQL个二货,不能先select一张表的数据,然后update这张表,sql如下:

update tab A set A.status=1 where A.id in (
select id from tab where start_time>now()
);
 

 

解决办法是欺骗这个二货,让他觉得没动过那张表,在外面包装一层。sql如下:
update tab A set A.status=1 where A.id in (
select B.id from(
select id from tab where start_time>now()
) B
);

来源:http://blog.sina.com.cn/s/blog_6e1d76db01018irb.html

posted @ 2013-10-15 16:35  在那花开时节  阅读(318)  评论(0)    收藏  举报