0

I have a table named Persons with the following data

The following query will fetch me the pid value in Persons table which is not equal to any of the PersonId values :

select B.pid
from Persons A
RIGHT JOIN Persons B ON (A.PersonID = B.pid)
where A.PersonID IS NULL
  AND B.pid IS NOT NULL

enter image description here

Is there a way to fetch the same data using LEFT OUTER JOIN?

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
  • possible duplicate of [Difference between left join and right join in SQL Server](http://stackoverflow.com/questions/4715677/difference-between-left-join-and-right-join-in-sql-server) – amdixon Sep 16 '15 at 12:06

1 Answers1

1

You should get the same result using left join, just by reversing the tables:

select B.pid
from Persons B LEFT JOIN
     Persons A
     ON A.PersonID = B.pid
where A.PersonID IS NULL AND B.pid IS NOT NULL
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • like... without using that B.pid IS NOT NULL in the original query.. will a left outer join help with that? –  Sep 16 '15 at 12:07