Bird
0
0

Given these tables:

medium📝 query result Q4 of 15
SQL - LEFT and RIGHT JOIN
Given these tables:

Students
id | name
1 | Dave
2 | Emma
3 | Frank

Enrollments
student_id | course
1 | Math
3 | Science

What will be the output of this query?

SELECT Students.name, Enrollments.course FROM Students LEFT JOIN Enrollments ON Students.id = Enrollments.student_id;
AOnly students who have enrollments in courses.
BAll students with their courses; students without courses show NULL for course.
CAll courses with their students; courses without students show NULL for student name.
DNo rows returned because of missing WHERE clause.
Step-by-Step Solution
Solution:
  1. Step 1: LEFT JOIN preserves all left rows

    Students is the left table, so all students appear in the result.
  2. Step 2: Matching enrollments

    Enrollments matched by student_id; unmatched students get NULL in course.
  3. Final Answer:

    All students with their courses; students without courses show NULL for course. -> Option B
  4. Quick Check:

    LEFT JOIN keeps all Students rows [OK]
Quick Trick: LEFT JOIN shows all left rows, unmatched right columns NULL [OK]
Common Mistakes:
MISTAKES
  • Thinking only matched rows appear
  • Confusing left and right tables
  • Assuming NULLs are filtered out

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes