Bird
0
0

Given tables Authors(id, name) and Books(id, author_id), what does this query return?

medium📝 query result Q4 of 15
SQL - Subqueries
Given tables Authors(id, name) and Books(id, author_id), what does this query return?
SELECT name FROM Authors a WHERE EXISTS (SELECT 1 FROM Books b WHERE b.author_id = a.id);
ANames of authors who have written at least one book
BNames of authors who have not written any books
CAll author names regardless of books
DNames of books written by authors
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the subquery

    The subquery checks if there exists any book with author_id matching the author's id.
  2. Step 2: Understand EXISTS behavior

    EXISTS returns true if the subquery returns any rows, so the main query selects authors with at least one book.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    EXISTS filters authors having related books [OK]
Quick Trick: EXISTS checks for existence of related rows [OK]
Common Mistakes:
MISTAKES
  • Confusing EXISTS with NOT EXISTS
  • Assuming it returns book names
  • Ignoring the correlation between subquery and outer query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes