Identifying Missing Matches in Mysql DB
1 answer
You can use left join:
SELECT animals.id FROM animals LEFT JOIN animals_food ON animals.id = animals_food.animals_id WHERE animals_food.food_id IS NULL;
A left join contains all rows from the left table (animals), even if the join condition does not find any matching rows on the right table (animals_food). When no match is found, the columns in the right table are replaced with NULL.
The WHERE clause in my query deletes all rows that have matches, leaving only the orphan axes from the left table in the result.
+3
a source to share