
将一个表中的某个字段插入到另一个表的字段,如何写SQL语句?
3个回答
展开全部
楼主说的是更新吧,楼上说的是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 一定要一一对应,不让会报错:查询单个值返回多条记录。
update a set col=(select col from b where a.id=b.id)
exists(select 1 from b where a.id=b.id )
注意:两个表的ID 一定要一一对应,不让会报错:查询单个值返回多条记录。
展开全部
注意:是插入还是更新?
插入的话:
insert into a(col) select col from b;
更新的话:
update a set col=select col from b where a.id=b.id;
插入的话:
insert into a(col) select col from b;
更新的话:
update a set col=select col from b where a.id=b.id;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
insert into table1(col1) select col2 from table2 where table1.id = table2.id
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |