What is a correlated subquery? Include an example
What will be an ideal response?
A correlated subquery uses the standard SQL subquery structure of a SELECT statement (called the lower SELECT) within the WHERE clause of a controlling (or upper) SELECT. However, where a non-correlated subquery uses different tables in the upper and lower SELECTS, the correlated subquery uses the same table in both SELECTS. SQL aliases are used to provide different table names within the query. When a non-correlated subquery is processed, the lower SELECT is processed first and the entire result set of the lower SELECT is passed to the upper SELECT. When a correlated subquery is processed, a nested processing is used where each individual result of the lower SELECT is returned one at a time to the upper SELECT for processing. Here is an example that finds the last names of all students advised by a faculty whose last name is 'Smith':
SELECT S.LastName
FROM Student S
WHERE EXISTS
(SELECT *
FROM FACULTY F
WHERE F.FacultyID = S.AdvisorID AND F.LastName = 'Smith'));
You might also like to view...
A company begins the week with a book value-per-share of $25. During the week it issues additional (common) shares at a price-per-share of $21. Compared to its (total) book value as of the beginning of the week, its new (total) book value is higher.
a. true b. false
A ________ is the amount of loss or damage that you agree to cover before any insurance coverage takes over
A) Deductible B) Carrying cost C) Premium D) Policy E) Liability