Home > database >  About the more child query, one of them is empty, the all data all have no, how to solve this proble
About the more child query, one of them is empty, the all data all have no, how to solve this proble

Time:10-05

About the more child query, one of them is empty, the all data all have no, how to solve the problem of the

Select * from
(select f1 from t1 where... ) a1,
(select f1 from t1 where... ) a2,
The from t2 (select f1 where... A3,
.

If there is no record of a1, even other sub queries, the main query didn't count, I think whether or not the subquery is there a number, as long as there is record, other sub queries can get, how to solve?

CodePudding user response:

The building Lord gives some test data, and your expected results, didn't see you want to achieve what kind of effect;

CodePudding user response:

The need to make sure that a piece of the main table, it means that there must be a data, the other may not, associated with outside connection line Anderson, d=b.i d (+) and Anderson, d=c.i d (+)
If can not, can use multiple union two two imprison LianZha it,

CodePudding user response:

Table t1
F1 rq
10 the 2016-10-13
F2 rq
20 2016-10-11

Select a1. F1, a1. F1 - a2. F1 from
(select f1 from t1 where rq='2016-10-13') a1,
(select f1 from t1 where rq='2016-10-12') a2

The 12th day no data, as a result, the main query didn't record
I don't think to realize even 12 data, but still can get data from 13, namely get 10

CodePudding user response:

Ahking
reference 3 floor response:
table t1
F1 rq
10 the 2016-10-13
F2 rq
20 2016-10-11

Select a1. F1, a1. F1 - a2. F1 from
(select f1 from t1 where rq='2016-10-13') a1,
(select f1 from t1 where rq='2016-10-12') a2

The 12th day no data, as a result, the main query didn't record
I don't think to realize even 12 data, but still can get data from 13, namely get 10

With a LEFT JOIN implementation

SQL> The select e. * from emp where e e.e mpno=7369;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
17-7369 SMITH at 7902-80, 800 in December 20

SQL> The select e. * from emp where e e.e mpno=7970;

Not selected row

SQL> The select e1. * from (select e. * from emp where e e.e mpno=7369) e1 left join
E. 2 (the select * from emp where e e.e mpno=7970) e2 on e1, empno=e2. Empno;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
17-7369 SMITH at 7902-80, 800 in December 20

CodePudding user response:

Outer join

 with t1 as 
(select 10 f1, '2016-10-13' rq from dual
Union all
Select 20 f1, '2016-10-11' rq from dual
)
Select a1. F1, a1. F1 - a2. F1 from
(select f1 from t1 where rq='2016-10-13') a1
Full join
(select f1 from t1 where rq='2016-10-12') a2
On 1=1

CodePudding user response:

Suggested that baidu oracle + left connect (connection),
With reference to your SQL, upstairs again understand left after connection
Please refer to the
http://bbs.csdn.net/topics/390152319

CodePudding user response:

5/f, external connection is ok

CodePudding user response:

The select f1 from t1 where.. Union select f2 from t2 where... Union select f3 from t3 where..

CodePudding user response:

reference 1st floor wmxcn2000 response:
the building Lord gives some test data, and your expected results, didn't see you want to achieve what kind of effect;
  • Related