Senator Guerra Souty original series calendar,replica hublot blue steel peach pointer collocation of rolex replica Rome digital scale, track type minute replica watches scale shows that the classical model is swiss replica watches incomparable, wearing elegant dress highlights.
mr-ponna.com

 

YOU ARE HERE: HOME Questions What is correlated sub query



About correlated sub-query

View(s): 33601

What is correlated sub-query?

Answer 1)


correlated sub-query is a term used for specific types of queries in SQL. It is a sub-query (a query nested inside another query) that uses values from the outer query in its WHERE clause. The sub-query is evaluated once for each row processed by the outer query.

Here is an example for a typical correlated sub-query. In this example we are finding the list of employees (employee number and names) having more salary than the average salary of all employees in that employee's department.

SELECT employee_number, name
FROM employee AS e1
WHERE salary > (SELECT avg(salary)
    FROM employee
    WHERE department = e1.department);

In the above query the outer query is,

SELECT employee_number, name
FROM employee AS e1
WHERE salary >

And the inner query is,

(SELECT avg(salary)
    FROM employee
    WHERE department = e1.department);

In the above nested query the inner query has to be executed for every employee as the department will change for every row. Hence the average salary will also change.

The effect of correlated sub-queries can also be obtained using outer Joins.


  Asked in:  iGATE   Expertise Level:  Intermediate
  Last updated on Friday, 21 March 2014
2/5 stars (14 vote(s))

Register Login Ask Us Write to Us Help