Bird
0
0

Which of the following SQL queries correctly finds unmatched rows from students table that have no matching enrollments?

easy📝 Syntax Q3 of 15
SQL - LEFT and RIGHT JOIN
Which of the following SQL queries correctly finds unmatched rows from students table that have no matching enrollments?
ASELECT s.* FROM students s INNER JOIN enrollments e ON s.id = e.student_id WHERE e.student_id IS NULL
BSELECT s.* FROM students s LEFT JOIN enrollments e ON s.id = e.student_id WHERE e.student_id IS NULL
CSELECT s.* FROM students s RIGHT JOIN enrollments e ON s.id = e.student_id WHERE s.id IS NULL
DSELECT s.* FROM students s FULL JOIN enrollments e ON s.id = e.student_id WHERE e.student_id IS NOT NULL
Step-by-Step Solution
Solution:
  1. Step 1: Use LEFT JOIN to keep all students

    LEFT JOIN keeps all rows from students and matches from enrollments.
  2. Step 2: Filter students without enrollments

    WHERE e.student_id IS NULL selects students with no matching enrollment.
  3. Final Answer:

    SELECT s.* FROM students s LEFT JOIN enrollments e ON s.id = e.student_id WHERE e.student_id IS NULL -> Option B
  4. Quick Check:

    LEFT JOIN + NULL filter finds unmatched students [OK]
Quick Trick: LEFT JOIN + WHERE right_table.key IS NULL finds unmatched rows [OK]
Common Mistakes:
MISTAKES
  • Using INNER JOIN which excludes unmatched rows
  • Using RIGHT JOIN incorrectly for this case
  • Filtering on NOT NULL instead of NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes