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
Written by Alberto Jauregui
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Protip
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#