Consider two tables Employees and Departments:
Employees: +----+----------+-----------+ | id | name | dept_id | +----+----------+-----------+ | 1 | Alice | 10 | | 2 | Bob | 20 | | 3 | Charlie | NULL | +----+----------+-----------+ Departments: +----+------------+ | id | dept_name | +----+------------+ | 10 | HR | | 30 | Marketing | +----+------------+
What is the result of this query?
SELECT e.name, d.dept_name FROM Employees e FULL OUTER JOIN Departments d ON e.dept_id = d.id ORDER BY e.name NULLS LAST, d.dept_name NULLS LAST;
SELECT e.name, d.dept_name FROM Employees e FULL OUTER JOIN Departments d ON e.dept_id = d.id ORDER BY e.name NULLS LAST, d.dept_name NULLS LAST;
FULL OUTER JOIN returns all rows from both tables. If there is no match, NULL fills the missing side.
The FULL OUTER JOIN returns all rows from Employees and Departments. Alice matches HR (dept_id=10). Bob's dept_id=20 has no matching department, so dept_name is NULL. Charlie has NULL dept_id, so no match on department side. Marketing department (id=30) has no matching employee, so name is NULL.
When using FULL OUTER JOIN between two tables, which statement about NULL values in the result is always true?
Think about what happens when a row in one table has no matching row in the other.
FULL OUTER JOIN returns all rows from both tables. When a row from one table has no match in the other, the columns from the unmatched table are filled with NULLs.
Which of the following FULL OUTER JOIN queries will cause a syntax error in PostgreSQL?
Check the operator used for equality in the ON clause.
PostgreSQL uses a single equals sign (=) for equality comparison. Using double equals (==) causes a syntax error.
You have two large tables, Orders and Shipments, joined by FULL OUTER JOIN on order_id. Which approach can improve query performance?
Indexes help speed up join operations on large tables.
Indexes on join columns allow the database to quickly match rows, improving FULL OUTER JOIN performance. CROSS JOIN produces a Cartesian product and is much slower. Removing filters usually increases data size. SELECT * fetches unnecessary data, slowing query.
You run this query:
SELECT e.id, e.name, d.dept_name FROM Employees e FULL OUTER JOIN Departments d ON e.dept_id = d.id WHERE d.dept_name = 'Sales';
You expect to see all employees in Sales department, but the result is empty. Why?
Think about how WHERE filters affect NULLs from unmatched rows.
The WHERE clause filters rows after the join. Rows where d.dept_name is NULL (employees without matching department) are excluded, so no rows appear if no department named 'Sales' exists. To include all employees with or without matching departments, use the condition in the JOIN ON clause or use LEFT JOIN.