A LEFT JOIN returns all rows from the left table and the matching rows from the right table. If there is no match, the result will contain NULL for columns from the right table.
Click to reveal answer
beginner
What is the difference between LEFT JOIN and RIGHT JOIN?
LEFT JOIN returns all rows from the left table and matching rows from the right table. RIGHT JOIN returns all rows from the right table and matching rows from the left table.
Click to reveal answer
beginner
In a RIGHT JOIN, what happens if there is no matching row in the left table?
If there is no matching row in the left table, the result will still include the row from the right table, but columns from the left table will be NULL.
Click to reveal answer
intermediate
Write a simple SQL query using LEFT JOIN to combine two tables: employees and departments.
SELECT employees.name, departments.department_name FROM employees LEFT JOIN departments ON employees.department_id = departments.id;
Click to reveal answer
intermediate
Why might you use a LEFT JOIN instead of an INNER JOIN?
You use LEFT JOIN when you want to keep all rows from the left table even if there is no matching row in the right table. INNER JOIN only returns rows with matches in both tables.
Click to reveal answer
What will a LEFT JOIN return if there is no matching row in the right table?
AAll rows from the right table
BNo rows
COnly rows with matching keys
DAll rows from the left table with NULLs for right table columns
✗ Incorrect
LEFT JOIN returns all rows from the left table and fills NULL for right table columns if no match exists.
Which JOIN returns all rows from the right table and matching rows from the left table?
ALEFT JOIN
BRIGHT JOIN
CINNER JOIN
DFULL JOIN
✗ Incorrect
RIGHT JOIN returns all rows from the right table and matching rows from the left table.
If you want to keep all employees even if they don't belong to a department, which JOIN should you use?
ALEFT JOIN
BRIGHT JOIN
CINNER JOIN
DCROSS JOIN
✗ Incorrect
LEFT JOIN keeps all rows from the left table (employees) even if no matching department exists.
What will happen if you use RIGHT JOIN but the right table has no rows?
AResult will be empty
BAll rows from left table returned
CAll rows from right table returned
DError occurs
✗ Incorrect
RIGHT JOIN returns all rows from the right table; if right table is empty, result is empty.
Which JOIN type can be thought of as the opposite of LEFT JOIN?
AINNER JOIN
BFULL JOIN
CRIGHT JOIN
DCROSS JOIN
✗ Incorrect
RIGHT JOIN is the opposite of LEFT JOIN, returning all rows from the right table.
Explain in your own words how LEFT JOIN works and when you would use it.
Think about keeping all your friends in a list even if some don't have phone numbers.
You got /4 concepts.
Describe the difference between LEFT JOIN and RIGHT JOIN with an example.
Imagine two lists: one is your friends, the other is their phone numbers.
You got /4 concepts.
Practice
(1/5)
1. What does a LEFT JOIN do in PostgreSQL?
easy
A. Returns all rows from the left table and matching rows from the right table, or NULL if no match.
B. Returns all rows from the right table and matching rows from the left table, or NULL if no match.
C. Returns only rows that have matching values in both tables.
D. Returns all rows from both tables, matching where possible.
Solution
Step 1: Understand LEFT JOIN behavior
A LEFT JOIN returns all rows from the left table regardless of matches in the right table.
Step 2: Check what happens with unmatched rows
If there is no matching row in the right table, the result includes NULLs for right table columns.
Final Answer:
Returns all rows from the left table and matching rows from the right table, or NULL if no match. -> Option A
Quick Check:
LEFT JOIN = all left rows + matched right rows [OK]
Hint: LEFT JOIN keeps all left rows, fills right with NULL if no match [OK]
Common Mistakes:
Confusing LEFT JOIN with RIGHT JOIN
Thinking LEFT JOIN returns only matched rows
Assuming unmatched rows are dropped
2. Which of the following is the correct syntax for a RIGHT JOIN in PostgreSQL?
easy
A. SELECT * FROM table1 RIGHT JOIN table2 ON table1.id = table2.id;
B. SELECT * FROM table1 JOIN RIGHT table2 ON table1.id = table2.id;
C. SELECT * FROM table1 RIGHT OUTER JOIN table2 WHERE table1.id = table2.id;
D. SELECT * FROM table1 RIGHT JOIN ON table1.id = table2.id table2;
Solution
Step 1: Recall correct RIGHT JOIN syntax
The correct syntax is: SELECT ... FROM left_table RIGHT JOIN right_table ON condition;
Step 2: Check each option
SELECT * FROM table1 RIGHT JOIN table2 ON table1.id = table2.id; matches the correct syntax exactly. Options B, C, and D have syntax errors or misplaced keywords.
Final Answer:
SELECT * FROM table1 RIGHT JOIN table2 ON table1.id = table2.id; -> Option A
Quick Check:
RIGHT JOIN syntax = FROM left_table RIGHT JOIN right_table ON condition [OK]
Hint: RIGHT JOIN syntax: FROM left_table RIGHT JOIN right_table ON condition [OK]
Common Mistakes:
Placing JOIN keyword incorrectly
Using WHERE instead of ON for join condition
Misordering table names
3. Given these tables:
employees id | name 1 | Alice 2 | Bob 3 | Carol
departments id | dept_name 2 | Sales 3 | HR 4 | IT
What is the result of this query?
SELECT employees.name, departments.dept_name FROM employees LEFT JOIN departments ON employees.id = departments.id ORDER BY employees.id;