Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 4002 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > SQL Server Interview Questions > What is diffrence between Co-related sub ...

What is diffrence between Co-related sub query and nested sub query ?

Interview question and answer by: Bharathi Cherukuri | Posted on: 4/23/2012 | Category: SQL Server Interview questions | Views: 573 | | Points: 40
Ads
Ads


Answer:

Correlated subquery runs once for each row selected by the outer query. It contains a reference to a value from the row selected by the outer query.

Example:

select e1.empname, e1.basicsal, e1.deptno from emp e1 

where e1.basicsal = (select max(basicsal) from emp e2 where e2.deptno = e1.deptno)



Nested subquery runs only once for the entire nesting (outer) query. It does not contain any reference to the outer query row.

Example:

select empname, basicsal, deptno from emp 

where (deptno, basicsal) in (select deptno, max(basicsal) from emp group by deptno)

Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Bharathi Cherukuri

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/20/2013 12:11:17 AM