Bird
0
0

You have two tables:

hard📝 Application Q8 of 15
PostgreSQL - Joins in PostgreSQL
You have two tables:
Students:
ID | Name
1 | John
2 | Jane
3 | Mike

Scores:
ID | Score
2 | 85
3 | 90
4 | 75

Write a query using FULL OUTER JOIN to list all students and scores, showing NULL where data is missing. Which query is correct?
ASELECT Students.ID, Name, Score FROM Students LEFT JOIN Scores ON Students.ID = Scores.ID;
BSELECT Students.ID, Name, Score FROM Students RIGHT JOIN Scores ON Students.ID = Scores.ID;
CSELECT Students.ID, Name, Score FROM Students FULL OUTER JOIN Scores ON Students.ID = Scores.ID ORDER BY Students.ID;
DSELECT Students.ID, Name, Score FROM Students INNER JOIN Scores ON Students.ID = Scores.ID;
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement for all students and scores

    FULL OUTER JOIN returns all rows from both tables, including unmatched ones with NULLs.
  2. Step 2: Evaluate options

    SELECT Students.ID, Name, Score FROM Students FULL OUTER JOIN Scores ON Students.ID = Scores.ID ORDER BY Students.ID; uses FULL OUTER JOIN correctly. Options A and C return only one side fully. SELECT Students.ID, Name, Score FROM Students INNER JOIN Scores ON Students.ID = Scores.ID; returns only matching rows.
  3. Final Answer:

    SELECT Students.ID, Name, Score FROM Students FULL OUTER JOIN Scores ON Students.ID = Scores.ID ORDER BY Students.ID; -> Option C
  4. Quick Check:

    FULL OUTER JOIN for all rows = B [OK]
Quick Trick: Use FULL OUTER JOIN to combine all rows from both tables [OK]
Common Mistakes:
  • Using LEFT or RIGHT JOIN instead of FULL OUTER JOIN
  • Forgetting ORDER BY for clarity
  • Using INNER JOIN which excludes unmatched rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes