今天做一个简的应用需要把把另外一个表某个字段内容复制到另一张表的某个字段了,当时想用php批量处理后来听同事说一个update就搞定了,结果查了一下真还不错,下面分享一下操作方法.
我想把article表中A字段的内容复制到article表中B字段里面sql语句为:
update article set B=A;
例子,代码如下:
- UPDATE file_manager_folder f1
- LEFT OUTER JOIN file_manager_folder f2
- ON f1.name = f2.name AND f2.parentId = 54
- SET f1.parentId = 54
- WHERE f2.name IS NULL AND f1.id IN (1,2,3);
sql语法这样写.
例子,代码如下:
- mysql> UPDATE v95_soft a
- RIGHT JOIN dp_softlist b ON a.id = b.softid
- SET a.catid = b.softclassid;
-
- mysql> UPDATE v95_soft set url = CONCAT(url,id);
-
- mysql> UPDATE v95_soft set url = CONCAT(url,catid);
-
- mysql> UPDATE v95_soft a
- RIGHT JOIN dp_softlist b ON a.id = b.softid
- SET a.start = b.softscore;
-
- mysql> UPDATE v95_soft a
- RIGHT JOIN dp_softlist b ON a.id = b.softid
- SET a.updatetime = UNIX_TIMESTAMP(b.softcreatedate);
- //开源软件:phpfensi.com
- mysql> update v95_soft set sysadd=1;
|