Distinguish between nested, correlated subquery and join operation-oracle SQL plsql interview question and answer
DIFFERENCE:
NESTED |
CORRELATED |
JOIN
OPERATION |
It is the
type of subqueries used in the SQL. |
It is the
type of subqueries used in the SQL. |
It is to
combine data from the multiple tables. |
It is running
independently. |
It depends on
the outer query. |
It combines
the data which is based on the common field. |
It is also
known as an inner query or nested query. |
It depends on
the values from the outer query. |
It is the
statement which is used to combine data or rows from two or more tables which
is based on the common field between them. |
Inner query
is executed first and the result is used by the outer query. |
Inner query
is executed for each row of the outer query. |
It will
combine the data from the multiple tables into the single result set. |
It is used
for filtering the data, performing calculations and joining the datasets
indirectly. |
It is used when
the inner query needs to reference values from the outer query. |
It is used when
you need to combine the data from more than one table or when the where
clause is not enough. |
select * from
emp where sal>(select avg(sal) from emp); |
select
e.ename from emp e where e.sal>(select avg(sal) from emp where
deptno=e.deptno); |
select e.
ename,d.dname from emp e join dept d ON e.deptno=d.deptno; |
It is used for
the complex calculations or filtering. |
It is used
for the complex calculations or filtering. |
It is the
best way to combine the data from the multiple tables. |
SYNTAX: Select column
from table where column in (select column from table); |
SYNTAX: Select column
from table where column= (select column from table where column=value); |
SYNTAX: Select column
from table1 join table2 ON table1.column=table2.column; |
In terms of performance,
it works better than the correlated query but is slower than the join
operation. |
In terms of performance,
it is slower than the nested and join operation. Both inner and outer queries
will be going to run. |
In terms of performance,
it is faster than the nested and correlated. |
Execution of
an inner query does not depend on the outer query. |
Inner query
needs the outer query for running. Dependency exists. |
Neither inner
nor outer query and there is no dependency exists. |
It is
suitable when the result of the inner query is compared with the outer query. |
It is
suitable when the inner query is get executed for each and every row of the
outer query. |
It is
suitable when the data from the multiple tables are combined and queries with
the where clause are not sufficient. |
Inner query run
first and only once in the bottom-up method and the result from the inner
query is used to run the outer query. |
Outer query
runs first and for each row of the outer query, the inner query runs. |
Cross product
strategy is applied when each row of one table is multiplied with another table
row. |
|
|
|
Comments
Post a Comment