LEFT JOIN
returns all matching records from the left table combined with the right table. Even if there are no matching records in the right table, the LEFT JOIN
will still return a row in the result, but with NULL in each column from the right table.
LEFT JOIN
is also known as LEFT OUTER JOIN
.LEFT JOIN
clause.SELECT column_1, column_2...
defines the columns from both tables where we want the data to be selected.FROM table_1
defines the left table as the main table in the FORM clause.RIGHT JOIN table_2
defines the right table as the table the main table joins.ON table_1.matching_field = table2.matching_field
sets the join condition after the ON keyword with the matching field between the two tables.LEFT JOIN
query as follows:
item_no
, item_name
, and sold_qty
, sold_price
columns as defined in the SELECT
clause.
NULL
value from the right table (invoice).
111
matches the item butter
and has been sold for 3pcs/9000.113
matches the item tea
but has never been sold. Thus the sold_qty & sold_price columns are filled with: null.116
matches the item Bread
and has been sold three times, for 6pcs/3000, 2pcs/10000, and 1pc/5000.119
matches the item Coffee
and has been sold two times, for 5pcs/20000 and 4pcs/16000.LEFT JOIN
: