• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

SQL QUERY

Hello Experts,

i need to do a update query that basically, matches 3 columns from two different tables and updates a column from table A to table B based on the 3 column from each table that equal each other.

Hope this helps solve my problem. i have tried doing a join put i get to many results on my select statement.
0
decoded
Asked:
decoded
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
decoded,

It sounds like you need an UPDATE WITH JOIN. In MS SQL, this looks like this:

UPDATE B
SET B.column = A.column
FROM tableA AS A
JOIN tableB AS B ON B.key1 = A.key1 AND B.key2 = A.key2 AND B.key3 = A.key3
;

Open in new window


When you have time for some light reading, a3's article http://www.experts-exchange.com/Database/Miscellaneous/A_1517-UPDATES-with-JOIN-for-everybody.html may be useful. It talks about MERGE that should be available to you now that you are on SQL 2008.

Hope that helps!

Kevin
0
 
decodedAuthor Commented:
awesome!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now