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 |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-05-25 : 06:58:09
|
| i have 2 table 1 with an identity column and toher columns too.the second with 2 columns of data that i use to find the exact ro with data to update it with the first table.so how can i take the detiales from table 2 and update them into the field of table 1 wit ha single UPDATE command?thnaksi n advancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-25 : 07:09:12
|
General ApproachUpdate T1 set col=T2.colfrom Table1 T1 inner join Table2 T2on T1.id=T2.id MadhivananFailing to plan is Planning to fail |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-05-25 : 07:34:12
|
| the proble is that i dont have "on T1.id=T2.id"but rather have " where t2.col1=13 and t2.datatype=29 "Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-25 : 07:35:25
|
| Then how do you match the records with table1?MadhivananFailing to plan is Planning to fail |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-05-25 : 08:41:37
|
| that the point i cant using inner joing or something like thatbeacuse forom the second table i have unique values for the row i needand all is left is to update the fildes from table to to 1Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-05-25 : 08:56:53
|
pelegk2Its very hard to understand what u need!! The answer given to u (by Madhi) is generic, because of the description of the question is so vague. Even ur next answer doesn't make much sense.U may need to tell how the 2 tables are related. (without any relationship, u won't be able to match records in 2 tables).Or give some sample data and expected results after updating.(Also please take some time in typing, to have less typo errors - so that v have to concentrate on SQL only )Srinika |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-05-25 : 21:18:55
|
did you know you can add a where clause on the update statement?the join fields are the ones that you need to identify which equals to your table1 and table2otherwise, play around with this...quote: from bolUPDATE titlesSET price = price * 2WHERE pub_id IN (SELECT pub_id FROM publishers WHERE pub_name = 'New Moon Books')
--------------------keeping it simple... |
 |
|
|
|
|
|