I have two related tables, Invoice Header and Invoice Detail. They have two key fields: Vendor# and Invoice#. What is the best way to find orphaned records - records in Detail table that have no match in Header table?
SELECT ....
FROM InvoiceHeader IH
FULL OUTER JOIN InvoiceDetail ID
ON IH.Vendor# = ID.Vendor#
AND IH.Invoice# = ID.Invoice#
WHERE IH.Invoice# IS NULL
OR ID.Invoice# IS NULL
The WHERE clause will filter out the records that are not orphaned leaving you with just the parent and child records that have no relationship.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.