I wish to update table1 with any distinct value of table2 matching the same code, no matter which one or the order (value from table2 can't be picked more than once)
+-------------------+ +--------------+
| table1 | | table2 |
+-------------------+ +--------------+
| id | code | value | | code | value |
+----+------+-------+ +------+-------+
| 1 | A | | <-- | A | v1 |
| 2 | A | | | B | v2 |
| 3 | B | | | A | v3 |
+----+------+-------+ | A | v5 |
| A | v6 |
+------+-------+
+-------------------+
| table1 |
+-------------------+
| id | code | value |
+----+------+-------+
| 1 | A | v6 |
| 2 | A | v3 |
| 3 | B | v2 |
+----+------+-------+
How can I write the SQL update statement ? (MySQL 5.7)