Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > CREATE TABLE table1 (id int, bla1 varchar(10), bla2 varchar(10), ucr varchar(10)); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO table1 VALUES (10001, 'ABC', 33, 'VALUE1'); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO table1 VALUES (10002, 'DEF', 44, 'VALUE2'); > > <pre> > ✓ > </pre> <!-- --> > CREATE TABLE table2 (id int, bla1 varchar(10), bla2 varchar(10), email varchar(100)); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO table2 VALUES (10001, 'TYU', 33, '1@1.com'); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO table2 VALUES (10002, 'FGT', 44, '2@2.com'); > > <pre> > ✓ > </pre> <!-- --> > CREATE TABLE dummy (ucr int, name varchar(100), email varchar(100)); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO dummy VALUES (10001, 'ABC', '1@1.com'); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO dummy VALUES (10002, 'DEF', '2@2.com'); > > <pre> > ✓ > </pre> <!-- --> > UPDATE table1 > JOIN table2 > ON table1.id = table2.id > JOIN dummy > ON dummy.email = table2.email > SET table1.ucr = dummy.ucr; > > <pre> > ✓ > </pre> <!-- --> > SELECT * > FROM table1; > > <pre> > id | bla1 | bla2 | ucr > ----: | :--- | :--- | :---- > 10001 | ABC | 33 | 10001 > 10002 | DEF | 44 | 10002 > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=mariadb_10.2&fiddle=819c5e8cb021b83ce41c1f9575c2a7d6)*
back to fiddle