将一个表中的某个字段插入到另一个表的字段,如何写SQL语句?

如题所述

楼主说的是更新吧,楼上说的是SQL SERVER的语法,不知道楼主是什么数据库,如果是oracle的话 建议这么写:
update a set col=(select col from b where a.id=b.id)
exists(select 1 from b where a.id=b.id )
注意:两个表的ID 一定要一一对应,不让会报错:查询单个值返回多条记录。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-02-28
注意:是插入还是更新?
插入的话:
insert into a(col) select col from b;
更新的话:
update a set col=select col from b where a.id=b.id;本回答被提问者采纳
第2个回答  2011-03-03
insert into table1(col1) select col2 from table2 where table1.id = table2.id