日期:2014-05-19  浏览次数:20504 次

求UPDATE语句
表格如下:
tab1
id   num   cc

tab2
id   num   cc

tab1和tab2中的num(唯一对应),但是id不同,cc不一定相同.

要求把tab1中的cc根据相应的num,改成tab2中的cc中的值




------解决方案--------------------
update tab1 set cc=b.cc from tab1 a,tab2 b where a.num=b.num
------解决方案--------------------
这样写,效率高些
update tab1 set cc=b.cc from tab1 a left join tab2 b on a.num=b.num
------解决方案--------------------
update tab1 set cc=b.cc
from tab1 a inner join tab2 b on a.num=b.num