Bird
0
0

Given the tables:

medium📝 query result Q4 of 15
PostgreSQL - Joins in PostgreSQL
Given the tables:
students(id, name)
enrollments(student_id, course)
What will be the result of this query?
SELECT students.name, enrollments.course FROM students INNER JOIN enrollments ON students.id = enrollments.student_id;
AList of all students with courses, including those without enrollments
BList of student names with their enrolled courses only for matching student IDs
CList of all enrollments with student names, including unmatched enrollments
DEmpty result if any student has no enrollment
Step-by-Step Solution
Solution:
  1. Step 1: Understand INNER JOIN effect on these tables

    INNER JOIN returns rows where students.id matches enrollments.student_id.
  2. Step 2: Analyze query output

    Only students with enrollments appear, showing their names and courses.
  3. Final Answer:

    List of student names with their enrolled courses only for matching student IDs -> Option B
  4. Quick Check:

    INNER JOIN returns matching student-course pairs [OK]
Quick Trick: INNER JOIN shows only matching student-course pairs [OK]
Common Mistakes:
  • Expecting all students regardless of enrollment
  • Expecting all enrollments regardless of student
  • Thinking unmatched rows appear in result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes