1

I have two databases database_a & database_b with the exact same structure, but different email data. How do I update all of database_b's email field with the ones from database_a based on the clients id number?

CREATE `clients` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `firstname` text NOT NULL,
  `lastname` text NOT NULL,
  `companyname` text NOT NULL,
  `email` text NOT NULL,
  `address1` text NOT NULL,

1 Answer 1

3

Use an UPDATE JOIN

UPDATE database_a.clients A INNER JOIN database_b.clients B
USING (id) SET B.email = A.email;

or

UPDATE database_a.clients A INNER JOIN database_b.clients B
ON A.id = B.id SET B.email = A.email;

Give it a Try !!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.