select a.* from 
book a,author b,address c
where a.id=b.parentid and b.id=c.parentid
 and ( city='北京' or authorname='张三')

解决方案 »

  1.   

    select * from book where rootid in(select rootid from address where city='北京') or rootid in(select rootid from author where authorname='张三')
    使用子查询,
    这样做效率是不高
      

  2.   

    select * from book as A where exists (select 1 from address where city='北京' and rootid = A.rootid) and exists (select 1 from author where authorname='张三' and rootid = A.rootid)
      

  3.   

    select a.* from book a 
     left join author b on a.id=b.parentid
     left join address c on b.id=c.parentid
    where ( c.city='北京' or b.authorname='张三')
      

  4.   

    select * from book where rootid in(select rootid from address where city='北京' or authorname='张三') 
    或:
    select * from book where exists (select 1 from address where (city='北京' or authorname='张三') and rootid=book.rootid) 
      

  5.   

    select * from book where exists (select 1 from address where (city='北京' or authorname='张三') and rootid=book.rootid)