Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
romeck
Starting Member
16 Posts |
Posted - 2014-04-18 : 14:02:59
|
ID VALUE1 VALUE21 | a | 122 | v | 33 | c | 44 | g | 12 BID IDA VALUE1 | 1 | 122 | 1 | 343 | 2 | 174 | 3 | 45 | 1 | 226 | 3 | 1Hi there i want to update A with values from b , so the value2 from a= value from b but only with latest coresponding data based on b.id so after updtate a looks like:ID VALUE1 VALUE2 1 | a | 22 couse max id from B with ida=1 is 5 and so the value is 22 , so A.value2=22 2 | v | 17 couse max id from B with ida=2 is 3 and so the value is 17 so A.value2=22 3 | c | 1 couse max id from B with ida=3 is 6 and so the value is 1 so A.value2=1 4 | g | 12 couse there is no ida=4 in B |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2014-04-18 : 14:43:00
|
Here's one way:update a set a.value2 = b.valuefrom ajoin b on b.ida = a.idwhere b.id = (select max(id) from b where ida = a.id ) Be One with the OptimizerTG |
|
|
|
|
|