Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Table without using column name

Status
Not open for further replies.

trenttc

Technical User
Feb 25, 2002
68
US
I have a table (TABLE1) updated by a second table (TABLE2) based on a common field (CODE). For each CODE match, there are from one to three TABLE1 fields (TYPE1,TYPE2,TYPE3) updated from a single TABLE2 field (GROUP). On the first match, the first GROUP value goes in TYPE1. On the next match (if there is a second match) the second GROUP value goes in TYPE2, etc.

TABLE1
CODE1 TYPE1 TYPE2 TYPE3
1234
2468
3456

TABLE2
CODE2 GROUP
1234 4
2468 5
3456 9
1234 2
2468 6
1234 7

Putting it another way ...
UPDATE TABLE1 SET
TABLE1.TYPE1 = TABLE2.GROUP 1st match
TABLE1.TYPE2 = TABLE2.GROUP 2nd match, if there is one
TABLE1.TYPE3 = TABLE2.GROUP 3rd match, if there is one
FROM TABLE1
INNER JOIN TABLE2
SELECT CODE2, GROUP,
ON TABLE1.CODE1 = TABLE2.CODE2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top