A-A+

update实现从一张表复制数据到另一张表中

2017年10月17日 PHP技术文章 暂无评论 阅读 0 views 次

今天做一个简的应用需要把把另外一个表某个字段内容复制到另一张表的某个字段了,当时想用php批量处理后来听同事说一个update就搞定了,结果查了一下真还不错,下面分享一下操作方法.

我想把article表中A字段的内容复制到article表中B字段里面sql语句为:

update article set B=A;

例子,代码如下:

  1. UPDATE file_manager_folder f1   
  2. LEFT OUTER JOIN file_manager_folder f2    
  3.     ON f1.name = f2.name AND f2.parentId = 54   
  4. SET f1.parentId = 54    
  5. WHERE f2.name IS NULL AND f1.id IN (1,2,3);   

sql语法这样写.

例子,代码如下:

  1. mysql> UPDATE v95_soft a    
  2. RIGHT JOIN dp_softlist b ON a.id = b.softid    
  3. SET a.catid = b.softclassid;   
  4.    
  5. mysql> UPDATE v95_soft set url = CONCAT(url,id);   
  6.    
  7. mysql> UPDATE v95_soft set url = CONCAT(url,catid);   
  8.    
  9. mysql> UPDATE v95_soft a    
  10. RIGHT JOIN dp_softlist b ON a.id = b.softid    
  11. SET a.start = b.softscore;   
  12.    
  13. mysql> UPDATE v95_soft a    
  14. RIGHT JOIN dp_softlist b ON a.id = b.softid    
  15. SET a.updatetime = UNIX_TIMESTAMP(b.softcreatedate);   
  16. //开源软件:www.xiariboke.net   
  17. mysql> update v95_soft set sysadd=1;  
标签:

给我留言