Junior — Middle
What does the LEFT JOIN operation in SQL do and what results does it return?
sobes.tech AI
Answer from AI
The LEFT JOIN operation in SQL is used to combine two tables in such a way that the resulting set includes all records from the left (first) table, and only matching records from the right (second) table based on the join condition.
If there are no matching records in the right table for a row from the left table, the fields from the right table will be filled with NULL in the result set.
Example:
SELECT A.id, A.name, B.order_date
FROM Customers A
LEFT JOIN Orders B ON A.id = B.customer_id;
This query will return all customers, including those without orders. For customers without orders, the order_date field will be NULL.