Custom Search

Sunday, September 16, 2007

What do you mean by Correlated sub query?

Sub queries, or nested queries, are used to bring back a set of rows to be used by the parent query. Depending on how the sub query is written, it can be executed once for the parent query or it can be executed once for each row returned by the parent query. If the sub query is executed for each row of the parent, this is called a correlated sub query.

A correlated sub query can be easily identified if it contains any references to the parent sub query columns in its WHERE clause. Columns from the sub query cannot be referenced anywhere else in the parent query. The following example demonstrates a non-correlated sub query.
E.g. Select * From CUST Where '10/03/1990' IN (Select ODATE From ORDER Where CUST.CNUM = ORDER.CNUM)

--
Oracle RDBMS

No comments: