使用join重写子查询

时间:2014-05-03 20:45:31

标签: join subquery

如何使用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)

1 个答案:

答案 0 :(得分:0)

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)