March 21st, 2013, 02:57 PM
Query/insert between 3 tables with only 2 columns matching between any two tables?
I've got a situation where I need to populate a new table column with all of the data from another table column.
This is the set up (the tables have more columns than this, but this is the issue):
Column 2 <-- New, empty.
I added a new column called 2 (just like exists in table B), and now I need to add the data from Table B's column 2 to into Table A's new column 2.
So it seems to me that I need to somehow select all Column 2 from table B, where Column 3 matches between tables B and C and Column 1 matches between tables A and C.
How do I write the query to do that?
Essentially, how do I write a query to do this:
select Column 2, Column 3 from TABLE B
Select Column 1, Column3 From Table C WHERE Column 3 = result of Column 3 above
Insert into Table A Column 2 result WHERE Column 1 = Column 1 from result from C above
[Edit: add pseudo query]
Last edited by we5inelgr; March 21st, 2013 at 04:11 PM.
March 21st, 2013, 04:15 PM
you want a joined update --
ON TableC.Column1 = TableA.Column1
ON TableB.Column3 = TableC.Column3
SET Table1.Column2 = TableB.Column2
Comments on this post
March 21st, 2013, 04:29 PM
awesome. many thanks!
March 21st, 2013, 04:38 PM
thanks for fixing the typo in the SET clause