Description
The SQL keyword LEFT JOIN is used to join two tables, which returns the data as mentioned below.
- The result set includes all the records from the left table.
- For the matching records between the tables, the data for the columns coming from the right table is pulled from the right table.
- For the non-matching records, a NULL value is used for the columns coming from the right table.
LEFT JOIN
The below SQL fetches data from specific columns of the joined tables.
SELECT order_id, order_date, order_value, customer_name
FROM orders
LEFT JOIN customers ON orders.customer_id = customers.customer_id;
LEFT JOIN All Columns
The below SQL fetches data from all columns of the joined tables.
SELECT *
FROM orders
LEFT JOIN customers ON orders.customer_id = customers.customer_id;