Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> correlated subquery
Hello,
I'm trying to understand correlated subquery, got result that puzzles
me.
Can't figure out the different results from the following queries,
typed the following original example on correlated subqueries from
sql-Reference
SELECT deptno, ename, sal
FROM emp emp_alias1
WHERE sal >
(SELECT avg(sal) FROM emp emp_alias2 WHERE emp_alias1.deptno = emp_alias2.deptno )
output:
DEPTNO ENAME SAL
---------- ---------- ----------
10 KING 5000 20 JONES 2975 20 SCOTT 3000 20 FORD 3000 30 ALLEN 1600 <- sal < avg(sal), why is this row selected? 30 BLAKE 2850
6 rows selected.
tried the same thing as simple subquery, made it stepwise
a) only subquery
SELECT avg(sal)
FROM emp;
output
AVG(SAL)
b) whole query
SELECT deptno, ename, sal
FROM emp
WHERE sal >
(SELECT avg(sal) FROM emp )
output:
DEPTNO ENAME SAL
---------- ---------- ----------
10 CLARK 2450 <- missing in correlated subquery 10 KING 5000 20 JONES 2975 20 FORD 3000 20 SCOTT 3000 30 BLAKE 2850
6 rows selected.
Any suggestions are welcome,
thanks a lot and have a nice day
... Manuela
Received on Tue Jan 30 2001 - 14:14:03 CST