โ† 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. What does NOT EXISTS return when its subquery yields no rows?

    Answer: TRUE

    NOT EXISTS is TRUE precisely when the subquery returns no rows.

  2. Which comparison returns rows greater than EVERY value the subquery returns?

    Answer: > ALL

    > ALL is true only when the value exceeds every value returned by the subquery.

  3. A NULL in a NOT IN subquery list can cause what problem?

    Answer: The whole predicate may return no rows unexpectedly

    NOT IN with a NULL in the list can yield UNKNOWN, filtering out rows you expected to keep.

  4. Which is generally preferred for performance when checking existence of related rows?

    Answer: EXISTS

    EXISTS can stop at the first matching row, often outperforming counting approaches.

  5. In SELECT salary, (SELECT AVG(salary) FROM emp) AS avg_sal, the inner query is a what?

    Answer: Scalar subquery in the SELECT list

    It returns one value placed in the SELECT list, making it a scalar subquery.

  6. What must a subquery in the FROM clause always have?

    Answer: An alias

    Derived tables in FROM must be named with an alias in most SQL dialects.

  7. Which keyword can replace IN for multi-row equality matching?

    Answer: = ANY

    = ANY is logically equivalent to IN, matching any value in the result set.