Click here to Skip to main content
16,020,305 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<pre></pre>


Hello,

I would like to know how do we correlate the queries with in the same table.
Please help me in having the knowledge.
Posted

1 solution

You can always do this by using aliases.
As an example see
SQL
SELECT name
 FROM employee AS e1
 WHERE salary > (SELECT avg(salary)
    FROM employee
    WHERE department = e1.department)


I actually got the query from this[^] site, and you can read more about correlated subqueries on that web page.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900