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
In a DELETE with a subquery in WHERE, what does the subquery typically provide?
Answer: A set of IDs identifying rows to delete
The subquery returns keys/values used to select which rows the DELETE removes.
What does SOME mean as a subquery quantifier?
Answer: It is a synonym for ANY
In SQL, SOME and ANY are interchangeable quantifiers with identical meaning.
Why might you wrap an aggregate in a subquery for comparison in WHERE?
Answer: Aggregates cannot be used directly in WHERE
Aggregate functions are not allowed directly in WHERE, so a subquery computes them first.
A subquery returning multiple rows used with = will cause what?
Answer: A runtime error
Equality expects a single value, so a multi-row subquery triggers an error.
What is a key advantage of a CTE over a repeated subquery?
Answer: It can be referenced multiple times by name and improves readability
A CTE defines a named result set reusable within the query and clarifies complex logic.
Which subquery placement lets you filter on a per-group computed maximum?
Answer: A correlated subquery in WHERE comparing to MAX per group
A correlated subquery can compute a group-specific MAX for filtering each outer row.
When using EXISTS, what should the subquery's SELECT list typically be?
Answer: Irrelevant, often SELECT 1
EXISTS only checks row presence, so the SELECT list is ignored and SELECT 1 is common.