Union和With Clause SubQuery Oracle

时间:2017-10-09 03:44:24

标签: oracle subquery

在生产中使用之前,我需要立即帮助解决问题:

在Oracle11g中使用以下SQL

With sub_query1 as (select t1.column1, t2.column2, t1.id from table1 t1
inner join table2 t2 on t1.id = t2.id )
SELECT t3.column3 s1.* FROM sub_query1 s1 
INNER JOIN table3 t3 ON t3.id=s1.id
union
SELECT t4.column4 s1.* FROM sub_query1 s1 
INNER JOIN table4 t4 ON t4.id=s1.id;

当我按原样使用时,这是有效的,但是当在SUB_QUERY1之前添加一个子查询它不起作用时,它只返回0行而没有任何错误 :< / p>

With 
main_sub_query as (select ta.id from tableA ta)
--second subquery
, sub_query1 as (select t1.column1, t2.column2, t1.id from table1 t1
inner join table2 t2 on t1.id = t2.id 
inner join main_sub_query mq ON mq.id=t1.id
)
SELECT t3.column3 s1.* FROM sub_query1 s1 
INNER JOIN table3 t3 ON t3.id=s1.id
union
SELECT t4.column4 s1.* FROM sub_query1 s1 
INNER JOIN table4 t4 ON t4.id=s1.id;

当我删除联盟以及之后的部分时,它会返回数据,不确定是什么问题。

0 个答案:

没有答案