In one of my projects, I had to find and delete duplicate rows in parent and child tables. So, I came up with following rough queries and kept here for my future references.
SELECT id, NAME, COUNT(role_id) AS numofroles FROM users GROUP BY NAME HAVING numofroles > 2 SELECT * FROM users WHERE NAME LIKE 'DANIEL HEILIG' SELECT COUNT(id) FROM users WHERE NAME LIKE 'DANIEL' SELECT * FROM fusions WHERE qe_inspector_id = 5027 SELECT * FROM fusions WHERE manufacturer_id = 5027 SELECT fusions.* FROM fusions INNER JOIN users ON fusions.manufacturer_id = users.id WHERE users.name LIKE 'continental' SELECT fusions.* FROM fusions WHERE fusions.manufacturer_id IN ( SELECT id FROM users WHERE NAME LIKE 'continental' ) UPDATE fusions SET manufacturer_id = 5011 WHERE ( SELECT fusions.id FROM fusions WHERE fusions.manufacturer_id IN ( SELECT id FROM users WHERE NAME LIKE 'continental' ) ) UPDATE fusions SET manufacturer_id = 5011 WHERE fusions.id IN ( 1717, 1722, 1727, 1732, 1737, 1742, 1747, 1752, 1757, 1762, 1766 ) DELETE FROM users WHERE role_id = 2 AND id <> 5011 SELECT * FROM users WHERE NAME LIKE 'continental' SELECT COUNT(fusions.excel_no) FROM fusions WHERE fusions.qe_inspector_id IN ( SELECT id FROM users WHERE NAME LIKE 'DANIEL' AND role_id = 12 ) SELECT fusions.excel_no FROM fusions WHERE fusions.qe_inspector_id IN ( SELECT id FROM users WHERE NAME LIKE 'DANIEL' AND role_id = 12 ) UPDATE fusions SET qe_inspector_id = 4567 WHERE fusions.id IN ( 629, 630, 631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654 ) DELETE FROM users WHERE NAME LIKE 'DANIEL'