Introduction
A FULL OUTER JOIN helps you combine rows from two tables, showing all matches and also rows that don't have a match in either table.
SELECT columns FROM table1 FULL OUTER JOIN table2 ON table1.common_column = table2.common_column;
SELECT * FROM employees FULL OUTER JOIN departments ON employees.department_id = departments.id;
SELECT orders.id, customers.name FROM orders FULL OUTER JOIN customers ON orders.customer_id = customers.id;
CREATE TABLE students ( id INT, name TEXT ); CREATE TABLE scores ( student_id INT, score INT ); INSERT INTO students VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie'); INSERT INTO scores VALUES (1, 85), (3, 90), (4, 75); SELECT students.id, students.name, scores.score FROM students FULL OUTER JOIN scores ON students.id = scores.student_id ORDER BY students.id NULLS LAST, scores.student_id NULLS LAST;
FULL OUTER JOIN do in PostgreSQL?Table A:Table B:SELECT COALESCE(A.ID, B.ID) AS ID, A.Name, B.City FROM A FULL OUTER JOIN B ON A.ID = B.ID ORDER BY ID;SELECT * FROM A FULL OUTER JOIN B ON A.id = B.id WHERE A.name = 'Alice';Employees(emp_id, name) and Departments(dept_id, emp_id, dept_name).Pass the test and this pattern moves unknown