Consider two tables: Employees and Departments. Employees may or may not belong to a department.
What is the output of this query?
SELECT e.name, d.department_name FROM Employees e LEFT JOIN Departments d ON e.department_id = d.id ORDER BY e.name;
CREATE TABLE Employees (id INT, name VARCHAR(20), department_id INT); CREATE TABLE Departments (id INT, department_name VARCHAR(20)); INSERT INTO Employees VALUES (1, 'Alice', 10), (2, 'Bob', NULL), (3, 'Charlie', 20); INSERT INTO Departments VALUES (10, 'HR'), (20, 'IT');
LEFT JOIN keeps all rows from the left table even if there is no matching row in the right table.
The LEFT JOIN returns all employees. For Bob, who has no department_id, the department_name is NULL.
Which situation best explains why a FULL OUTER JOIN is useful?
Think about when you want to see everything from both tables, even if no match exists.
FULL OUTER JOIN returns all rows from both tables, filling NULLs where no match exists.
Which option contains a syntax error in the JOIN clause?
SELECT a.id, b.value FROM TableA a JOIN TableB b ON a.id = b.a_id;
Check where the join condition is placed.
JOIN requires the ON clause for the join condition, not WHERE.
You have two large tables and want to join them efficiently. Which approach is best?
Indexes help speed up joins by quickly matching rows.
INNER JOIN with indexes and early filtering reduces data processed and speeds query.
Given these tables:
Orders(order_id, customer_id) Customers(customer_id, name)
Query:
SELECT o.order_id, c.name FROM Orders o JOIN Customers c ON o.customer_id = c.customer_id;
Why might this query return duplicate rows for the same order?
Check if the join keys are unique in both tables.
If Customers has duplicate customer_id, each order matches multiple customers, causing duplicates.