mysql 更新带子查询(注意)

来源:互联网 发布:hfs for windows 破解 编辑:程序博客网 时间:2024/04/29 18:44

现在要做一下数据移植,需要更新相关的数据,需要在mysql中更新时不能将更新的表作为查询的表。

总结一下:

一:单表更新时

例如: update customer set category = 1 WHERE  deleteflag = 0 and name = '22';

注意不要子查询,mysql是不允许的。

二:带子查询的复杂更新

如:

update tb a,

(select  time,name

from tt )b 

set time4=b.col

where a.name=b.name and a.time1=b.time;

 

注意点:

1、update 时,更新的表不能在set和where中用于子查询;

2、update 时,可以对多个表进行更新(sqlserver不行);

         如:update ta a,tb b set a.Bid=b.id ,b.Aid=a.id;  

3、update 后面可以做任意的查询,这个作用等同于from;

0 0
原创粉丝点击