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 |
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-03-06 : 15:50:58
|
| I havetable T2id amount ss1 14 22 15 13 16 24 17 2table T3id amount ss1 3 11 4 22 5 13 6 24 7 24 8 14 9 1I runUPDATE t2, t3 SET t2.amount = t3.amountWHERE t2.id1=t3.id and t3.ss=1; T2 becomesID1 amount ss1 3 22 5 13 16 24 9 2but I want t2 to be ID1 amount ss1 3 22 5 13 16 24 8 2how can I do that?Thanks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-06 : 16:17:53
|
Try thisUPDATE T2SET T2.Amount = x.AmountFROM T2INNER JOIN ( SELECT ID, MIN(Amount) AS Amount FROM T3 WHERE SS = 1 ) AS x ON x.ID = T2.ID Peter LarssonHelsingborg, Sweden |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-03-06 : 16:19:01
|
| Why 8 and not 9? It is because you want the MIN() amount that matches? If so, then you can simply write it that way. instead of joining to T3, join to a SELECT statement that gives you one value per id and returns the MIN() of the amount column.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-03-06 : 16:21:49
|
... or, you could just cut and paste peso's code ...peso -- at least give them a few minutes to come up with the solution on their own ! - Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-06 : 16:24:15
|
Yes I could. But I waited 27 minutes first... Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|