22智能在线
新记
将一个表中的某个字段插入到另一个表的字段,如何写SQL语句?
如题所述
举报该文章
相关建议 2011-02-28
楼主说的是更新吧,楼上说的是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 一定要一一对应,不让会报错:查询单个值返回多条记录。
温馨提示:内容为网友见解,仅供参考
当前网址:
https://22.t2y.org/zz/f0h6tctsf.html
其他看法
第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
相似回答
大家正在搜
相关问题
sql语句把一个表的字段插入到另外一个表
把一个表中的某一属性的信息转到另一个表中sql语句怎么写
sql语句从一张表查询一个字段值插入另一个表中
SQL语句 怎么把从一个表中查出来数据插入到另一个表中
将一个数据库其中的一个表的某一列,插入到另一个数据库中某一个...
mysql如何更新一个表中的某个字段值等于另一个表的某个字段...
这个SQL语句怎么写:将一个字段里的值复制添加到另一个字段中
怎样用sql语句,在oracle中将一个表中查出来的字段插入...