Complete the code to select all columns from both tables using a full outer join.
SELECT * FROM employees [1] departments ON employees.dept_id = departments.id;The FULL OUTER JOIN returns all rows when there is a match in one of the tables. It combines the results of both left and right joins.
Complete the code to join orders and customers tables showing all orders and customers, matching by customer_id.
SELECT orders.id, customers.name FROM orders [1] customers ON orders.customer_id = customers.id;Using FULL OUTER JOIN ensures all orders and all customers appear, even if some orders have no customer or some customers have no orders.
Fix the error in the join clause to correctly perform a full outer join between products and sales.
SELECT products.name, sales.amount FROM products [1] sales ON products.id = sales.product_id;The correct syntax for a full outer join in PostgreSQL is FULL OUTER JOIN. Using just FULL JOIN also works but FULL OUTER JOIN is clearer and standard.
Fill both blanks to create a full outer join that shows all employees and their projects, matching by project_id.
SELECT employees.name, projects.title FROM employees [1] projects [2] employees.project_id = projects.id;
The join type is FULL OUTER JOIN and the condition is specified with ON. The WHERE clause is not used for join conditions here, and USING requires matching column names.
Fill all three blanks to write a full outer join query that selects employee names, department names, and handles unmatched rows.
SELECT employees.name AS employee_name, departments.name AS department_name FROM employees [1] departments [2] employees.dept_id = departments.id [3] employees.name IS NULL OR departments.name IS NULL;
The query uses FULL OUTER JOIN to include all rows. The join condition is specified with ON. The WHERE clause filters rows where either side is unmatched (NULL).