Bird
0
0

How would you modify this query to include students without enrollments?

hard📝 Application Q9 of 15
SQL - INNER JOIN
How would you modify this query to include students without enrollments?
SELECT Students.name, Courses.course_name FROM Students INNER JOIN Enrollments ON Students.student_id = Enrollments.student_id INNER JOIN Courses ON Enrollments.course_id = Courses.course_id;
AUse CROSS JOIN instead of INNER JOIN
BAdd WHERE clause filtering NULL enrollments
CChange second INNER JOIN to RIGHT JOIN
DChange first INNER JOIN to LEFT JOIN to include all students
Step-by-Step Solution
Solution:
  1. Step 1: Identify requirement

    Including students without enrollments means keeping all students even if no matching enrollment exists.
  2. Step 2: Use LEFT JOIN for first join

    Changing first INNER JOIN to LEFT JOIN keeps all students and matches enrollments if any.
  3. Step 3: Evaluate other options

    Add WHERE clause filtering NULL enrollments filters out NULLs, which excludes unmatched students. Change second INNER JOIN to RIGHT JOIN changes second join but does not affect students without enrollments. Use CROSS JOIN instead of INNER JOIN creates all combinations, not desired.
  4. Final Answer:

    Change first INNER JOIN to LEFT JOIN to include all students -> Option D
  5. Quick Check:

    LEFT JOIN keeps all left table rows [OK]
Quick Trick: Use LEFT JOIN to keep all rows from left table [OK]
Common Mistakes:
MISTAKES
  • Using INNER JOIN excludes unmatched rows
  • Misusing RIGHT JOIN in this context
  • Adding WHERE filters that remove unmatched rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes