Subqueries

 A subquery is a SELECT statement nested within another SQL statement. Subqueries are useful when you must execute multiple queries to solve a single problem.

project management training courses malaysia


Each query portion of a statement is called a query block. In the following query, the subquery in parentheses is the inner query block:

iot training courses malaysia


SELECT first_name, last_name FROM employees WHERE department_id IN ( SELECT department_id FROM departments WHERE location_id = 1800 );

The inner SELECT statement retrieves the IDs of departments with location ID 1800. These department IDs are needed by the outer query block, which retrieves names of employees in the departments whose IDs were supplied by the subquery.

itil training courses malaysia


The structure of the SQL statement does not force the database to execute the inner query first. For example, the database could rewrite the entire query as a join of employees and departments, so that the subquery never executes by itself. As another example, the Virtual Private Database (VPD) feature could restrict the query of employees using a WHERE clause, so that the database queries the employees first and then obtains the department IDs. The optimizer determines the best sequence of steps to retrieve the requested rows.

devops training courses malaysia


Comments

Popular posts from this blog

MICROSOFT SYSTEM CENTER TROUBLESHOOTING AND MAINTENANCE SERVICES COMPANY MALAYSIA

LEADING AND BEST IOS APP DEVELOPMENT COMPANY MALAYSIA