Merging Tables

cprobertson1

Registered User.
Local time
Today, 19:26
Joined
Nov 12, 2014
Messages
36
I have a table that has somehow dropped some of it's data in a particular Column (I can only assume it's been a botched SQL statement somewhere along the line - though why it's only dropped some of the data and not the others is beyond me)

Anyway - I have a backup of the table, and want to merge the "complete" column from the backup with the "corrupt" column from the main table - matching them by their Primary Key

I was originally planning on simply running a drop of SQL through a query to fix it - but I just cannot get my head round it for some reason.

Can anybody point me in the right direction for which SQL function I want to use here?



----
Ps - basically a "replace Column B with the same column from the backup table, matching up the ID numbers - which makes me think it's going to be one of the union or join functions)

--EDit--
It just occurred to me I may have posted this thread in the wrong subforum, my apologies if I have!
 
I have a table that has somehow dropped some of it's data in a particular Column (I can only assume it's been a botched SQL statement somewhere along the line - though why it's only dropped some of the data and not the others is beyond me)

Anyway - I have a backup of the table, and want to merge the "complete" column from the backup with the "corrupt" column from the main table - matching them by their Primary Key

I was originally planning on simply running a drop of SQL through a query to fix it - but I just cannot get my head round it for some reason.

Can anybody point me in the right direction for which SQL function I want to use here?



----
Ps - basically a "replace Column B with the same column from the backup table, matching up the ID numbers - which makes me think it's going to be one of the union or join functions)

--EDit--
It just occurred to me I may have posted this thread in the wrong subforum, my apologies if I have!

Take a look at this to get an idea:
http://stackoverflow.com/questions/224732/sql-update-from-one-table-to-another-based-on-a-id-match

Best,
Jiri
 
Nailed it! Took some experimenting, but eventaully got it with:
Code:
UPDATE Table1
INNER JOIN Table2 
ON Table1.column1 = table2.column1
SET Table1.column2 =table2.column2

Thanks! :D
 

Users who are viewing this thread

Back
Top Bottom