What will be the opposite of inner join? For a table table Person (int PersonId, varchar PersoName, int AddrId)
, I want to know the rows in Person with bad Ad
I think the best solution would be using EXISTS
. Like this:
SELECT * FROM Person P
WHERE P.AddrId IS NOT NULL
AND NOT EXISTS ( SELECT 1 FROM Address A WHERE A.AddrId = P.AddrId )
The query above will return every person that the AddrId is set but does not have a corresponding record in the Address table.
Obs.: Use the constant 1 in the EXISTS
query to avoid table access.