โ† 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. How many times does a correlated subquery conceptually execute?

    Answer: Once per outer-query row

    A correlated subquery is re-evaluated for each row processed by the outer query.

  2. Which returns rows less than AT LEAST ONE value from the subquery?

    Answer: < ANY

    < ANY is true if the value is less than at least one returned value.

  3. Can a subquery appear in the HAVING clause?

    Answer: Yes, to compare against aggregated results

    Subqueries are valid in HAVING to filter groups based on computed or external values.

  4. What is the result type expected by an IN subquery?

    Answer: A single column of values

    An IN subquery should return one column whose values are compared for membership.

  5. Which often performs better than a correlated subquery for the same logic?

    Answer: A JOIN

    Rewriting a correlated subquery as a JOIN frequently lets the optimizer run it more efficiently.

  6. What does = ALL require for the comparison to be TRUE with multiple distinct values?

    Answer: It cannot be TRUE since one value cannot equal several different ones

    = ALL is TRUE only if the value equals every returned value, impossible when they differ.

  7. A subquery feeding an INSERT ... SELECT statement does what?

    Answer: Supplies the rows to insert

    INSERT ... SELECT uses the subquery's result set as the rows to be inserted.