Mysql – Update table from another database

MySQL

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,

Best Answer

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 !!!