Posted on 2011-10-12
Last Modified: 2012-06-27
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.
Question by:decoded
    LVL 59

    Accepted Solution


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

    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 may be useful. It talks about MERGE that should be available to you now that you are on SQL 2008.

    Hope that helps!


    Author Closing Comment


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now