我现在有两张表,table1,table2,关联的字段是id现在是想把table2中的字段ggg更新到table1中的ggg中请问,要怎么写update table1 set a.ggg=b.ggg from table1 a,table2 b where a.ccid=b.ccid;我这样写有什么错吗 ?请指教
update table1 a set a.ggg= (select b.ggg from table a,table b where a.ccid=b.ccid) where a.ccid=(select b.ccid from table b);
update table1 set a.ggg=(select b.ggg from table2 b where a.ccid=b.ccid);
update table1 a set a.ggg=(select b.ggg from table2 b where a.ccid=b.ccid);
hebo2005()为什么在后面还要加一句where a.ccid=(select b.ccid from table b);不是非常理解。本人觉的update table1 set a.ggg=(select b.ggg from table2 b where a.ccid=b.ccid);就可以了啊。
hebo的重复了; 直接update table1 set a.ggg=(select b.ggg from table2 b where a.ccid=b.ccid);就可以了。
update table1 a set a.ggg=(select b.ggg from table2 b where a.ccid=b.ccid);
要加where a.ccid=(select b.ccid from table b)这个条件,否则你会把A表中的GGG赋为同一个值的.
where a.ccid=(select b.ccid from table b);
直接update table1 set a.ggg=(select b.ggg from table2 b where
a.ccid=b.ccid);就可以了。