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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 update with inner join

Author  Topic 

jaybat12
Starting Member

4 Posts

Posted - 2006-06-16 : 15:46:37
in a table TBL1 I have to set DESCRIPTION for a TYPE1 equal to DESCRIPTION for a TYPE2 where their ID is equal in TBL1 and their key fields appear together in another table TBL2. In english, in TBL1 the description and id are equal but the type is different. a relationship between their key fields is shown in TBL2. Any thoughts on how to write this?

SreenivasBora
Posting Yak Master

164 Posts

Posted - 2006-06-16 : 16:12:05
Provide a simple exmple, it is easy to understand ...

With Regards
BSR
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-19 : 02:15:25
General Approach

Update T
set col=S.col
from TargetTable T inner join SourceTable S
on T.keycol=S.keycol

Otherwise post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jaybat12
Starting Member

4 Posts

Posted - 2006-06-19 : 08:52:13
In the example below I have to set the description of part 100085 equal to the description of part 100095.


TBL1
PART DESCRIPTION UNIQUE_ID
100095 Handle Assembly 1242
100085 100085 1275

TBL2
UNIQUE_ID_1 UNIQUE_ID_2
1242 1275
Go to Top of Page

jaybat12
Starting Member

4 Posts

Posted - 2006-06-19 : 08:55:10
The example above doesn't look much like I wanted it to. TBL1 has columns PART, DESCRIPTION, UNIQUE_ID. Part 100095 has description 'Handle Assembly' and unique_id 1242. part 100085 has description 100085 and unique_id 1275. TBL2 has columns UNIQUE_ID_1, UNIQUE_ID_2.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-19 : 09:41:30
[code]update t1
set t1.DESCRIPTION = t3.DESCRIPTION
from TBL1 t1 inner join TBL2 t2
on t1.UNIQUE_ID = t2.UNIQUE_ID_2
inner join TBL1 t3
on t2.UNIQUE_ID_1 = t3.UNIQUE_ID[/code]


KH

Go to Top of Page

jaybat12
Starting Member

4 Posts

Posted - 2006-06-20 : 13:17:40
that does it. thanks.
Go to Top of Page
   

- Advertisement -