Bird
0
0

You wrote this query to find all students and their courses:

medium📝 Debug Q14 of 15
SQL - Table Relationships
You wrote this query to find all students and their courses:
SELECT Student.Name, Course.Title FROM Student
JOIN StudentCourse ON Student.ID = StudentCourse.StudentID
JOIN Course ON Course.ID = StudentCourse.CourseID
WHERE StudentCourse.StudentID = Student.ID;

But it has a problem. What is the problem?
AThe WHERE clause is redundant and causes a syntax error
BMissing alias for tables causes ambiguity
CThe WHERE clause is unnecessary because JOIN already matches IDs
DStudentCourse.CourseID is missing in the WHERE clause
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the JOIN conditions

    The JOINs already match Student.ID to StudentCourse.StudentID and Course.ID to StudentCourse.CourseID.
  2. Step 2: Check the WHERE clause

    The WHERE clause repeats the JOIN condition, which is unnecessary but not an error; however, it does not filter or add value.
  3. Final Answer:

    The WHERE clause is unnecessary because JOIN already matches IDs -> Option C
  4. Quick Check:

    JOIN matches IDs, WHERE clause redundant [OK]
Quick Trick: JOIN conditions handle matching; WHERE often not needed here [OK]
Common Mistakes:
MISTAKES
  • Assuming WHERE clause causes syntax error
  • Adding unnecessary conditions that duplicate JOINs
  • Confusing alias usage with errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes