A correlated subquery is a subquery that references a column from a table referred to in the parent statement. A correlated subquery is evaluated once for each row processed by the parent statement. The parent statement can be a Select, Update, or Delete statement.A correlated subquery answers a multiple-part question in which the answer depends on the value in each row processed by the parent statement. For example, you can use a correlated subquery to determine which employees earn more than the average salaries for their departments. In this case, the correlated subquery specifically computes the average salary for each department.SELECT select_listFROM table1 t_alias1WHERE expr rel_operator(SELECT column_listWHERE t_alias1.columnUPDATE table1 t_alias1SET column =(SELECT exprFROM table2 t_alias2DELETE FROM table1 t_alias1WHERE column rel_operator(SELECT exprFROM table2 t_alias2
![]()
Correlated column names in correlated subqueries must be explicitly qualified with the table name of the parent.This statement returns data about employees whose salaries exceed their department average. It assigns an alias to emp, the table containing the salary information, and then uses the alias in a correlated subquery:This example finds the department number (deptno) with multiple employees:
| © 2012 Progress Software Corporation and/or its subsidiaries or affiliates. |