Using Subqueries to Solve Queries
- Who has a sal greater than Scott’s ?
Subquery Syntax :- SELECT select_list FROM table WHERE expr operator (SELECT select_list FROM table);
- The subquery (inner query) executes once before the main query (outer query)
- The result of the subquery is used by the main query
Using a Subquery :- SELECT ename FROM emp WHERE sal > (SELECT sal FROM emp WHERE ename = ‘Scott');
Guidelines for Using Subqueries :- Enclose subqueries in parentheses
- Place subqueries on the right side of the comparison condition
- The ORDER BY clause in the Subquery is not needed unless you are performing Top-N analysis
- Use single-row operators with single-row subqueries, and use multiple-row operators with multiple-row subqueries
Types of Subqueries :
No comments:
Post a Comment