Link to home
Start Free TrialLog in
Avatar of Guru Ji
Guru JiFlag for Canada

asked on

SQL Update Query joining two different databases

Hi have two databases

Current and CurrentBackup

Both have exact same structure the only thing I want is to move data from field int6 from CurrentBackup to Current based on id

So here is the table structure
Current
id
int6

CurrentBackup
id
unt6

Please help me how to transfer all int6 data based on matching id from currentback to current in one query.

Thanks
Avatar of Michael Dyer
Michael Dyer
Flag of United States of America image

since the two tables have the same structure, you should be able to run this:

INSERT INTO  CurrentBackup.unt6
SELECT * FROM Current.int6
Avatar of Guru Ji

ASKER

I want to match the id as well.  so that the data entered into Current should be with matching id of CurrentBackup
ASKER CERTIFIED SOLUTION
Avatar of Chris Luttrell
Chris Luttrell
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
Avatar of Guru Ji

ASKER

Hi Chris,

I am not getting any data with the first select statement. Though I verified that there is data.

If I put WHERE CT.int6 = CBT.int6
Then it shows just one row which I remember edited manually.

Do you why I am not getting any data ?
Is one of them NULL?
in that case change it to
WHERE COALESCE(CT.int6, -9999) <> COALESCE(CBT.int6, -9999)
Avatar of Guru Ji

ASKER

Thank you so much Chris
Glad to help!
Avatar of Guru Ji

ASKER

Hi Chris,

Another question, please help
sure, looking at it now
taking a look at it now! :)