Insert value Into TableA From TableB Where multiple fields match in both

Posted on 2014-08-06
Medium Priority
Last Modified: 2014-08-06
Hopefully the title sums it up but:


I'm working in SQL Server 2008.  

I need to get the value from col1 in Table_A and insert it into col1 in Table_B where Table_A.col2 = Table_B.col2, and TableA.col3 = Table_B.col3, and Table_A.col4 = TableB.col4

The relationship is one to many Table_A to Table_B.

Hopefully that makes enough sense.  

Thanks in advance!!!
Question by:ttist25
LVL 36

Accepted Solution

ste5an earned 2000 total points
ID: 40244018
This is not an INSERT, it's an UPDATE. It's almost like your description:

SET     col1 = A.col1
FROM    Table_A A
        INNER JOIN Table_B B ON A.col2 = B.col2
                                AND A.col3 = B.col3
                                AND A.col4 = B.col4;

Open in new window


Author Comment

ID: 40244262
Worked a treat!  Thank you sir!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

850 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