Bird
0
0

Given tables:

medium📝 query result Q13 of 15
SQL - Advanced Joins
Given tables:
Students(id, name),
Enrollments(student_id, course_id),
Courses(id, title)
What will the query below return?
SELECT Students.name, Courses.title FROM Students JOIN Enrollments ON Students.id = Enrollments.student_id JOIN Courses ON Enrollments.course_id = Courses.id;
AList of all students and all courses regardless of enrollment
BList of student names with the titles of courses they are enrolled in
CList of courses with no students enrolled
DSyntax error due to missing WHERE clause
Step-by-Step Solution
Solution:
  1. Step 1: Analyze JOINs in the query

    Students join Enrollments on student ID, then Enrollments join Courses on course ID, linking students to their courses.
  2. Step 2: Understand SELECT output

    The query selects student names and course titles for matching enrollments, showing which student is in which course.
  3. Final Answer:

    List of student names with the titles of courses they are enrolled in -> Option B
  4. Quick Check:

    JOINs link students to their courses [OK]
Quick Trick: JOIN chains link related data stepwise [OK]
Common Mistakes:
MISTAKES
  • Thinking JOIN returns all combinations without conditions
  • Expecting courses without students to appear
  • Assuming WHERE is required for JOIN

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes