Bird
0
0

Given tables:

hard📝 Application Q9 of 15
SQL - Advanced Joins
Given tables:
Students with 2 rows: John, Jane
Courses with 3 rows: Math, Science, Art
Which query returns all student-course pairs but only for courses starting with 'S'?
ASELECT Students.name, Courses.course FROM Students CROSS JOIN Courses WHERE Courses.course = 'S';
BSELECT Students.name, Courses.course FROM Students CROSS JOIN Courses WHERE Courses.course LIKE 'S%';
CSELECT Students.name, Courses.course FROM Students CROSS JOIN Courses WHERE Students.name LIKE 'S%';
DSELECT Students.name, Courses.course FROM Students INNER JOIN Courses;
Step-by-Step Solution
Solution:
  1. Step 1: Use CROSS JOIN for all pairs

    We want all combinations of Students and Courses, so CROSS JOIN is correct.
  2. Step 2: Filter courses starting with 'S'

    Use WHERE clause with LIKE 'S%' on Courses.course to select courses starting with 'S'. SELECT Students.name, Courses.course FROM Students CROSS JOIN Courses WHERE Courses.course LIKE 'S%'; does this correctly.
  3. Final Answer:

    SELECT Students.name, Courses.course FROM Students CROSS JOIN Courses WHERE Courses.course LIKE 'S%'; -> Option B
  4. Quick Check:

    Filter courses with LIKE 'S%' after CROSS JOIN [OK]
Quick Trick: Filter with WHERE and LIKE after CROSS JOIN [OK]
Common Mistakes:
MISTAKES
  • Filtering on wrong table or column
  • Using INNER JOIN with ON for filtering
  • Using equality instead of LIKE for prefix

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes