mysql update更新带子查询的实现方式
2017-06-27 21:30
239 查看
现在要做一下数据移植,需要更新相关的数据,需要在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;
参考的文章:感谢原创,弄了半天才弄出来,看到这里,豁然开朗。
http://blog.csdn.net/xys_777/article/details/5793565
总结一下:
一:单表更新时
例如: 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;
参考的文章:感谢原创,弄了半天才弄出来,看到这里,豁然开朗。
http://blog.csdn.net/xys_777/article/details/5793565
相关文章推荐
- 转载:mysql update更新带子查询的实现方式
- JavaScript实现二级、多级(N级)联动下拉列表框更新版,支持IE6,FireFox,函数和类两种调用方式,支持到N级,非常通用。
- 用ISAPI方式实现Web页面的自动更新
- OpenJweb 1.6中自定义组合查询条件的实现方式
- 带子查询的更新语句
- Silverlight实现查询建模(四) 更新XAP包
- SQL 在查询中插入行号--自定义分页的另外一种实现方式
- MSSQL 实现 MySQL 的 limit 查询方式
- 六种方式实现hibernate查询,及IDE推荐
- .Net 分页实现系列之三---基于有查询条件的分页的方式 (1-13 11:38)
- 史上最强jquery1.3.2轻松打造div模式层! asp.net和html和MagicAjax实现3种方式! 已更新!
- SQL 在查询中插入行号--自定义分页的另外一种实现方式
- Access数据库:它已经被别的用户以独占方式打开,操作必须使用一个可更新的查询,不能锁定文件
- 301永久重定向实现方式及302重定向(再次更新)
- JavaScript实现二级、多级(N级)联动下拉列表框更新版,支持IE6,FireFox,函数和类两种调用方式,支持到N级,非常通用
- JavaScript实现二级、多级(N级)联动下拉列表框更新版,支持IE6,FireFox,函数和类两种调用方式,支持到N级,非常通用。
- 实现Google.cn Web方式下查询功能
- 新写的一个使用ASP.NET AJAX中的UpdatePanel控件实现GridView的无刷新删除,更新,添加,查询!
- MSSQL 如何实现 MySQL 的 limit 查询方式
- 树形查询新特性CONNECT_BY_ISLEAF的9i实现方式