Writing Subqueries Flashcards
7 cards from real SQL practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Writing Subqueries flashcards as text
Which keyword tests whether a subquery returns any rows at all?
Answer: EXISTS
EXISTS returns TRUE if the subquery produces one or more rows.
A subquery that references a column from the outer query is called what?
Answer: Correlated subquery
A correlated subquery depends on a column supplied by the outer query and runs per outer row.
What does a scalar subquery return?
Answer: A single value
A scalar subquery returns exactly one row and one column, i.e., a single value.
Which operator lets a value match ANY result from a subquery returning multiple rows?
Answer: IN
IN checks whether a value matches any value in the subquery's result set.
Where can a subquery used as a derived table appear?
Answer: In the FROM clause
A derived table is a subquery placed in the FROM clause and must be given an alias.
What is required when a subquery is compared with = (equals)?
Answer: It must return a single value
Using = with a subquery requires the subquery to return exactly one value, or an error occurs.
Which clause CANNOT typically contain a subquery in standard SQL?
Answer: The keyword list of an INDEX definition
Subqueries appear in SELECT, FROM, WHERE, and HAVING, but not within an index column definition.