Question

I have two databases, and I need to UPDATE variable 'birthday' from one row to another checking 'name' (from db1 to db2).

The problem is, that 'name' variable in second db is located in another table (table2). It is possible to do this without changing DB structure using 'id' variable from db2 to synchronizing?

UPDATE `db1`.`table1`, `db2`.`table2` SET `db2`.`table1`.`birthday` = `db1`.`table1`.`birthday` WHERE `db2`.`table1`.`name` ... 

Scheme:

 db1-> table1 -> name,birthday
 db2-> table1 -> name,id     
       table2 -> birthday,id
Was it helpful?

Solution

UPDATE `db.1`.table1 AS t11
JOIN `db.2`.table1 AS t21 ON t11.name = t21.name
JOIN `db.2`.table2 AS t22 ON t21.id = t22.id
SET t11.birthday = t22.birthday
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top