Last Updated: February 25, 2016
·
1.558K
· albertojauregui

Find orphan rows in MySQL

There is a query to find quickly the orphan rows in one table with a left join reference.

SELECT t1.id_referencing_t2
FROM a_table AS t1
LEFT JOIN referenced_table AS t2
ON t1.id_referencing_t2 = t2.primary_id_of_t2
WHERE t2.primary_id_of_t2 IS NULL