Bird
0
0

Given tables Student, Course, and junction table StudentCourse with data:

medium📝 query result Q4 of 15
SQL - Table Relationships
Given tables Student, Course, and junction table StudentCourse with data:

Student: (1, 'Alice'), (2, 'Bob')
Course: (101, 'Math'), (102, 'Science')
StudentCourse: (1, 101), (1, 102), (2, 101)

What will this query return?
SELECT s.Name, c.Name FROM Student s JOIN StudentCourse sc ON s.ID = sc.StudentID JOIN Course c ON c.ID = sc.CourseID WHERE c.Name = 'Math';
AOnly Alice
BAlice and Bob
COnly Bob
DNo results
Step-by-Step Solution
Solution:
  1. Step 1: Understand the join and filter

    The query joins students to courses via the junction table and filters courses named 'Math'.
  2. Step 2: Check which students have 'Math'

    StudentCourse shows Alice (1) and Bob (2) both linked to course 101 'Math'.
  3. Final Answer:

    Alice and Bob -> Option B
  4. Quick Check:

    Join + filter on 'Math' returns both students [OK]
Quick Trick: Join junction table and filter on course name to find students [OK]
Common Mistakes:
MISTAKES
  • Assuming only one student has 'Math'
  • Ignoring the junction table links
  • Misreading join conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes