126k views
5 votes
A co-related subquery is executed for each tuple of the outer query. This means that its search condition refers to at least one attribute of the outer query.

Option 1: Co-related Subquery
Option 2: Non-co-related Subquery
Option 3: Nested Subquery
Option 4: Aggregate Subquery

User Bdereta
by
7.0k points

1 Answer

4 votes

Final answer:

The correct option for a subquery that is executed for each tuple of the outer query and refers to one of its attributes is a co-related subquery (Option 1). Co-related subqueries differ from non-co-related subqueries, which can run independently, and from aggregate subqueries, which return a single value.

Step-by-step explanation:

The subject of the question is related to a type of SQL subquery behavior, specifically pertaining to how a subquery relates to an outer query when executing a command in a database. The type of subquery being described is one that is executed for each tuple (row) of the outer query and where its search condition uses one or more attributes from the outer query. This description fits the definition of a co-related subquery. Therefore, the correct option from the given choices is Option 1: Co-related Subquery.

As a contrast, a non-co-related subquery is a type of subquery that can be run independently of the outer query and then the result is used by the outer query. An aggregate subquery is a subquery that returns a single value using an aggregate function like SUM or AVG. A nested subquery is a broader term that can refer to either correlated or non-co-related subqueries, but it's more often used to refer to non-co-related subqueries.

In practice, a co-related subquery might look something like this:

SELECT a.*
FROM TableA a
WHERE EXISTS (
SELECT 1
FROM TableB b
WHERE b.MatchColumn = a.MatchColumn)

In this example, the subquery involves TableB and is co-related because it uses an attribute from the outer query's TableA (MatchColumn) in its WHERE clause, and it is run for each tuple of TableA.

User Udondan
by
8.2k points