如何将一个表的一个列数据插入到另一个表 [英] how to insert one column data of one table to another table

查看:93
本文介绍了如何将一个表的一个列数据插入到另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我有两个表t1,t2

t1中的数据是

插入t1(id,name,address)值(1,Sunil,gurgaon)
插入t1(id,name,address)值(2,Ashok,Delhi)

1苏尼尔·纳瑙尔
2 Ashok Narrajnaul


表t2中的数据

插入t2(id,name)值(1,Sunil)
插入t2(id,name)值(2,Ashok)

1个Sunil NULL
2 Ashok NULL

现在,我想将表t1的地址添加到表t2的地址中,此时t2地址中的当前值为null.
请给我查询.

请帮帮我

Hello friends

I have two tables t1,t2

data in t1 is

insert into t1(id,name,address) values (1,Sunil,gurgaon)
insert into t1(id,name,address) values (2,Ashok,Delhi)

1 Sunil Narnaul
2 Ashok Narrajnaul


data in table t2

insert into t2(id,name) values (1,Sunil)
insert into t2(id,name) values (2,Ashok)

1 Sunil NULL
2 Ashok NULL

Now I want to insert addess of table t1 into address of table t2 at present values in address of t2 is null.
Pls send me query for this.

Pls Help me out

推荐答案

如果您只是想将表t1中的地址列中的数据填充到t2中相应行的地址中,(我的意思是将数据),您可以尝试 sql中的光标 [
If you just want to populate the data from address column in table t1 into address of corresponding row of t2, (i mean just to transfer the data) you can try the cursors in sql[^] way.

The Sql cursors should be kept a last option before using them as a part of stored procedures.


HTH
Rajeev


Please vote and mark the answer as accepted if this helps


这对您有用吗?
Would this work for you?
update t2
set address=t1.address
from t2
join t1 on t2.id=t1.id
where t2.address is null


这篇关于如何将一个表的一个列数据插入到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆