What is the difference between normal and corelated subqueries?
Answers were Sorted based on User's Feedback
Answer / arun joy
"Correlated" means it is linked back to the main query. For
example:
SELECT * FROM dept d
WHERE EXISTS
( SELECT 1 FROM emp
WHERE deptno = d.deptno );
This means: for each row in DEPT, go and check in EMP for a
row with the same deptno, and if you find one, report
success. Logically you are asking for the EXISTS check to
be repeated for every single row in DEPT (although the
optimizer may turn it into a hash join or similar if it
decides that will be more efficient). The fact that the
WHERE clause of the subquery refers back to the main query
makes it a correlated subquery.
Now if you'd just said:
SELECT * FROM dept d
WHERE EXISTS
( SELECT 1 FROM emp );
then Oracle can perform the subquery once only at the
start. Once it's confirmed that there is at least 1 record
in EMP then it knows not to re-run the subquery for each
row in DEPT.
Another non-correlated example:
SELECT * FROM dept d
WHERE d.deptno IN
( SELECT deptno
FROM emp
WHERE job = 'CLERK' );
Logically you are asking it to first find the set of
DEPTNOs in EMP that meet the condition, then use that to
retrieve the relevant rows from DEPT.
Is This Answer Correct ? | 14 Yes | 1 No |
Answer / deva
corelated subquery is the one where the in-query takes the
input from the outer query. This happens for every value in
the in-query.
Is This Answer Correct ? | 12 Yes | 2 No |
How to assign values to data fields in record variables?
What is null value in oracle?
You create a private database link and upon connection, fails with: ORA-2085: connects to . What is the problem? How would you go about resolving this error?
Table Has C1 And C2 Column If Exits any record in c1 then Update c2 record Otherwise insert new record in the C1 And C2 (Using Procedure)
Please send me Informatica 8.1 certification dumps, my mail id mona85gupta@gmail.com
18. Display the clientno and total value for all orders placed by that client. Output the result in the following format: Client <clientno> has placed orders to the value of <total value>
find out the third highest salary?
92 Answers CIPL, Cyber Shot, HCL, Hewitt, IBM, JPMorgan Chase, Orion, Verizon,
How can we view last record added to a table?
How to view all columns in an existing table?
Can objects of the same schema reside in different tablespace?
How to drop an existing view in oracle?
Explain mutating triggers.