I have 2 different databases on 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 the DB1.contacts.contacts table, where DB2.paperworks.name = DB1.contacts.name
My expected output should be:
Second table after DB2.paperworks query:
id | name | contact_id
1 | foo | 210
This is my request:
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 the condition "MAX (code)". Can you help me please?
source
share