Google
Information Storage and Retrieval: Nested Subquery and Correlated Subquery

Pages

Monday, January 6, 2014

Nested Subquery and Correlated Subquery

A subquery is a query which is used in the WHERE clause of a query. A subquery is nested when you are having subquery in the WHERE or HAVING clause of another subquery.

e.g

select Firstname, lastname from student where studentid in (select studentidfrom studentcourse where courseid in (select courseid from course wherecoursename='Oracle'))

In this case, innermost query is executed first and the results are passed on to outer query.

Corelated subquery is the reverse of nested subquery. In a corelated subquery the outer query is executed first and for each row of outer query, the inner query is executed.

select Coursename ,Courseadminid,(select student_name from student where studentid=Course.courseadminid)as CourseAdminName from course




No comments: