根据另一个表的列替换sql列值 [英] Replacing a sql column value based on a column another table

查看:24
本文介绍了根据另一个表的列替换sql列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下表所示的 table1 (col1,col2) 和 table2(col1,col2)/

I have table1 (col1,col2) and table2(col1,col2) as given below/

现在我需要将 table1 的 col2 的值替换为 table2 中 col1 和 col2 的相应值.所以决赛桌应该是这样的.我们如何在查询中做到这一点??

Now i need to replace values of col2 of table1 with corresponding value of col1 and col2 from table2. So that the final table should look like this. how can we do this in query??

推荐答案

我假设 table1.col2 和 table2.col2 具有相同的文本类型(?)

I assume table1.col2 and table2.col2 have the same text type(?)

update table1 set table1.col2=table2.col2
from table1 
join table2 on (table1.col2=table2.col1)

这篇关于根据另一个表的列替换sql列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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