- SQL code
--TABLE1ID NAME AGE1 小張 182 小王 203 小明 22--TABLE2ID NAME AGE001 小王 18002 小明 20003 小明004 小張 22
表結構應該是這樣的,TABLE1的NAME不會重複,而TABLE2的NAME會重複,要根據TABLE1和TABLE2的NAME把TABLE1的AGE賦到TABLE2對應的AGE上..最好有2種做法...
------解决方案--------------------
update table2 tt
set tt.age = (select v.age
from (select t1.id,
t1.name,
(select t.age
from table1 t
where t.name = t1.name) age
from table2 t1) v
where v.id = tt.id)
不知道是否可以,数据量大的话,这样的更新感觉会比较耗时
------解决方案--------------------
2种写法???
来个update 来个merge么 哈哈
------解决方案--------------------
Have a try.[code=SQL]
update table2
set table2.age =
(select table1.age from table1 where table1.name = table2.name);code]
------解决方案--------------------