Left join – SQL
In SQL, a LEFT JOIN (also called a LEFT OUTER JOIN) is a way to combine data from two or more tables based on a related column between them. It returns all rows from the left table, and any matching rows from the right table. If there is no match, NULL values are returned for right table’s columns.
Here is the syntax for a LEFT JOIN in SQL:
SELECT column1, column2, ...
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
Here’s an example that joins the “customers” and “orders” tables on the “customer_id” column:
SELECT customers.name, orders.order_date
FROM customers
LEFT JOIN orders
ON customers.customer_id = orders.customer_id;
This will return all rows from the “customers” table, along with any matching rows from the “orders” table. If a customer has no orders, NULL values will be returned for the “orders.order_date” column.