日期:2014-05-17  浏览次数:20804 次

oracle双表合并查询
有三张表A、B、C,其中B、C的外键'aid'是A的主键。但是A中的记录不会同时出现在B、C中。现有两条语句:
select b_val from B where aid in (select id from A where ...);
select c_val from C where aid in (select id from A where ...);
请高手指点一下我该怎么把这两句合并成一句,谢谢!!!
Oracle select 合并

------解决方案--------------------
select * from b left join c on b.aid=c.aid where b.aid in (select id from A where ...) 
------解决方案--------------------
select b_val
  from (select b_val, aid
          from B
        union all
        select c_val, aid from c) t
 where t.aid in (select id from A where .. .)