Link to home
Start Free TrialLog in
Avatar of aberns
abernsFlag for United States of America

asked on

subquery? Update column in one table with value from another table

Using MySQL, I am trying to update one column in Table1 with the value from another column in  Table2. I guess I need a subquery, but I am not sure how to go about it.  Previously, there was not an autoincrement primary key in the Table2. Instead, the primarykey was derived from meta data. So, to fix this problem, I added an autoincrement primary key to each Table2 record. But now I have to update each Table1 record with the new primary key from Table2. The match can be the OLD primary key (the derived one), which is in both tables. Note, the old faux primary key is a VARCHAR, not an integer, if that matters.
ASKER CERTIFIED SOLUTION
Avatar of mankowitz
mankowitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
-- THIS IS WHAT U NEED

update T1
set T1.key=T2.key
FROM  table1 T1 Inner Join table2 T2 on T1.oldkey=T2.oldkey