Difference between sub query and nested query ?
Answer Posted / sunil
A correlated Subquery runs for the rows selected from the outer query. It takes the value from the outer query
and execute the inner query for that value
example:
select * from emp e
where e.deptno in(select d.deptno from dept d
where e.deptno = d.deptno);
in this query emp table's deptno will be passed into the inner query(select deptno from dept d where e.deptno = d.deptno).
And the inner query will execute only for that value from the outer query.
That's why it is called correlated subquery
In Nested subquery the inner query runs only once and pass the result set to the outer query.
example
select * from emp e
where e.deptno in(select d.deptno from dept d);
Here the inner query (select d.deptno form dept d) will run first and fetches all the rows from the dept table
and the outer query will select only the records that has the matching deptno in the result set fetched by the
inner query. The outer query will act as a nesting query and that is why this is called nested subquery.
Here in correlated subquery, the outer query executes first and the inner query will execute second.
But in Nested subquery, the inner query executes first and the outer query executes second.
Hope this helps.
thanks to binosh who helped me to understand this concept before posting here...
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
How to apply filtering criteria at group level in oracle?
Why does for update in oracle 8 cause an ora-01002 error?
What is the difference between $oracle_base and $oracle_home?
What are a query and state the different types of queries and their uses?
Is oracle a language?
What exactly do quotation marks around the table name do?
What is transport network substrate (tns) in oracle?
What are dml statements in oracle?
How to generate query output in html format?
What are the different editions of oracle?
How to delete an existing row from a table in oracle?
What is an oracle table?
In XIR2 if we lost the administration password .How can we regain the password?thanks in advance.
1) Does oracle have any table which contain all the exceptions and it's code internally?
What is difference between truncate and delete?