SQL Joining Multiple Tables 2 — Questions and Answers
Question 1: Which join returns only rows that have matching values in both tables?
- INNER JOIN (Correct answer)
- LEFT JOIN
- FULL OUTER JOIN
- CROSS JOIN
Correct answer: INNER JOIN
INNER JOIN returns only the rows where the join condition matches in both tables.
Question 2: A LEFT JOIN between Customers and Orders returns customers with no orders. What appears in the Orders columns for those rows?
- NULL (Correct answer)
- 0
- Empty string
- The row is excluded
Correct answer: NULL
Unmatched rows from the right table produce NULL values in the result.
Question 3: Which clause is used to specify the matching condition in a join?
- ON (Correct answer)
- WHERE
- HAVING
- USING ONLY
Correct answer: ON
The ON clause specifies the condition that links the joined tables.
Question 4: What does a CROSS JOIN produce?
- The Cartesian product of both tables (Correct answer)
- Only matching rows
- Only the left table's rows
- Distinct rows from both tables
Correct answer: The Cartesian product of both tables
A CROSS JOIN pairs every row of the first table with every row of the second.
Question 5: Which keyword lets you join a table to itself?
- Use table aliases (Correct answer)
- SELF JOIN keyword
- RECURSIVE
- DOUBLE JOIN
Correct answer: Use table aliases
A self join references the same table twice using different aliases.
Question 6: In 'SELECT * FROM A JOIN B USING (id)', what does USING require?
- A column named id in both tables (Correct answer)
- A primary key on A only
- Identical row counts
- A WHERE clause
Correct answer: A column named id in both tables
USING joins on a column that exists with the same name in both tables.
Question 7: Which join returns all rows from both tables, matched where possible and NULL-filled otherwise?
- FULL OUTER JOIN (Correct answer)
- INNER JOIN
- LEFT JOIN
- CROSS JOIN
Correct answer: FULL OUTER JOIN
FULL OUTER JOIN combines LEFT and RIGHT joins, keeping all rows from both sides.
Which join returns only rows that have matching values in both tables?