两个表之间更新数据
来源:百度知道 编辑:UC知道 时间:2024/05/22 17:14:45
有表1
table1 table2
id count id tid count
1 2 1 1 5
2 4 2 2 7
3 5 3 3 9
4 3 6
其中tid为表一中的id
怎么用一条语句把表2中的count更新至表一相对应的count中
我这么写了说执行效率太低,有没有更好的办法呢
table1 table2
id count id tid count
1 2 1 1 5
2 4 2 2 7
3 5 3 3 9
4 3 6
其中tid为表一中的id
怎么用一条语句把表2中的count更新至表一相对应的count中
我这么写了说执行效率太低,有没有更好的办法呢
应该是用SQL语句吧?
update table1 set count=table2.count from table2 where table2.tid=table1.id
这样就可以实现table1表的更新了
=====================================================================================
这已经是最好的方法了好不好.
而且效率很高啊,这是直接连接两上表来更新数据.
sql语句:
update table1 set count=table2.count from table2 where table2.numeber=table1.number
应该就可以了!