Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UPDATE names n1
- JOIN names n2 ON (n1.id < n2.id AND n1.name = n2.name)
- JOIN child_table c ON (n2.id = c.id)
- SET c.name_id = n1.id
- ORDER BY n1.id DESC;
- DELETE FROM n2
- USING names n1 JOIN names n2 ON (n1.id < n2.id AND n1.name = n2.name);
- update dependent_table set name_id = <id you want to keep> where name_id in (
- select id from names where name = 'foo' and id != <id you want to keep>)
Add Comment
Please, Sign In to add comment