Um die Bestelltabelle zu aktualisieren, etwa so:
update orders
join regions r1
on r1.id = orders.region_id
set orders.region_id =
(
select min(r2.id)
from regions r2
where r2.name = r1.name
)
Danach können Sie doppelte Zeilen löschen mit:
delete regions
from regions
where id not in
(
select id
from (
select min(id) as id
from regions
group by
name
) as SubqueryAlias
)
Die doppelte Unterabfrage ist erforderlich, um den MySQL-Fehler ERROR 1093 (HY000) at line 36: You can't specify target table 'regions' for update in FROM clause
.