문제

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
도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top