What is Left Join in SQL?

The left join is used to retrieve rows which are common between the tables and all rows of the Left-hand side table. It returns all the rows from the Left-hand side table even though there are no matches on the Right-hand side table.

A Left Join in SQL is a type of join operation that returns all the rows from the left table (the table mentioned first in the query) and the matched rows from the right table (the table mentioned second in the query). If there is no match in the right table, NULL values are returned for columns from the right table.

The basic syntax for a Left Join is as follows:

SELECT column1, column2, ...
FROM table1
LEFT JOIN table2 ON table1.column_name = table2.column_name;

In this example, table1 is the left table, and table2 is the right table. The ON clause specifies the condition for the join.

For instance, if you have a table of customers (customers) and a table of orders (orders), a Left Join would return all customers and their orders if they have any. If a customer has no orders, the columns from the orders table will contain NULL values.

SELECT customers.customer_id, customers.customer_name, orders.order_id
FROM customers
LEFT JOIN orders ON customers.customer_id = orders.customer_id;

This query would return all customers along with their orders, or NULL values in the order_id column if a customer has no orders.