有A、B张表,其记录如下:
A表
c1 c2
--------------
1 a1
2 a2
3 a3
8 a8
B表
c1 c3
--------------
1 b1
2 b1
3 b3
10 b10
A.c1与B.c1相等,用一条sql语句,实现A.c2的值更新为B.c3
------------------------
UPDATE A
SET A.c2 =B.c3
from A ,B
where A.c1=B.c1
UPDATE A
SET A.c2 =B.c3
from A inner join B on A.c1=B.c1
注意:update后面是不能跟多表的,但跟在from子句后面
-------------------------------------------
另外,下面是一个mysql语句的多表更新
--------------------------------------------
update sk_general a,
(select a.gid, b.id
from (select gid, eid from sk_general where eid = 140) as a
left join sk_army b on a.gid = b.gid) as c
set a. status = 0
where c.gid = a.gid
and c.id is null;