首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

oracle双表合龙查询

2013-06-19 
oracle双表合并查询有三张表A、B、C,其中B、C的外键aid是A的主键。但是A中的记录不会同时出现在B、C中。现有两

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 .. .)

热点排行