What is the difference between LEFT JOIN and FULL JOIN operators in SQL when joining tables?
sobes.tech AI
Answer from AI
The LEFT JOIN and FULL JOIN operators are used to combine rows from two tables but differ in which rows they include in the result.
-
LEFT JOIN returns all rows from the left table and the matching rows from the right table. If there is no match in the right table, the right table's fields will be filled with NULL.
-
FULL JOIN (or FULL OUTER JOIN) returns all rows from both tables. If there is no match for a row from the left table in the right table, the right table's fields will be NULL, and vice versa — if there is no match for a row from the right table in the left table, the left table's fields will be NULL.
Example:
-- LEFT JOIN
SELECT * FROM A LEFT JOIN B ON A.id = B.a_id;
-- FULL JOIN
SELECT * FROM A FULL JOIN B ON A.id = B.a_id;
Thus, LEFT JOIN preserves all rows from the left table, while FULL JOIN includes all rows from both tables.