Question

How would I go about rewriting the subquery below using join.

select name 
from person p 
where exists (select * 
from friends r, person p2 
where r.name1 = p.name and p2.name = r.name2 and p.address = p2.address)
Was it helpful?

Solution

select 
  p1.name
from 
  friends r 
  inner join person p1 on (p1.name=r.name1)
  inner join person p2 on (p2.name=r.name2 and p2.address=p1.address)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top