โ† All SQL Flashcard Decks

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
  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.