I have 2 different database in my MySql server.
First table DB1.contacts:
id | name | code
1 | foo | 157
2 | foo | 95
3 | foo | 210
Second table DB2.paperworks:
id | name | contact_id
1 | foo | 0
I would like to update DB2.paperworks, set DB2.paperworks.contact_id = max(DB1.contacts.code) of DB1.contacts.contacts table where DB2.paperworks.name = DB1.contacts.name
My desidered output should be:
Second table after query DB2.paperworks:
id | name | contact_id
1 | foo | 210
This is my query:
UPDATE DB2.paperworks
JOIN DB1.contacts
ON DB2.paperworks.name = DB1.contacts.name
SET DB2.paperworks.contact_id = DB1.contacts.code
I don't understand how to write che "MAX(code)" condition. Can you help me, please?