Introduction:
Ø A Subquery or inner query is a query within another SQL query and embedded within the WHERE clause.
Ø Subqueries are used with the SELECT, INSERT, UPDATE, DELETE Statements along with the SQL operators like (=, <, >, >=, <=, IN, BETWEEN).
Types of Subquery:
Non correlated subquery:
ØIn terms of non correlated subquery the
inner query executed or valuated and the result of the inner query is as an
input to the outer query.
Example:
Output:
Correlated subquery:
Ø The inner query is dependent on the
outer query, which means both the inner and outer query executed side by side.
Example: 1
Select max(sal) from emp ;
Reference: Maximum salary of the employee is 5000
Output:
Example: 2
Output:
The way of correlated sub query works:
Step: 1
Get candidate key from Outer query.
Step: 2
Execute the inner query using the
candidate key value.
Step: 3
Use values from inner query to qualify
or disqualify candidate row.
Example: 3
Output:
No comments:
Post a Comment