In MySQL, LEFT JOIN
is used to fetch all records from LEFT side table (tablename1) and only matching records from right side table (tablename2). It appears immediately after the FROM clause.
To fetch all records from LEFT side table (tablename1) and only matching records from right side table (tablename2), use the following syntax:
Parameters:
tablename1 & tablename2: The table name from which you want to fetch records.
col1: The column or field name that will be return.
LEFT JOIN
, both have matching column values in tables :
Note:
In the above example, we are fetching all "accountName" fields value from "tblbankdemataccountcharges" table only matching record from "banks" field from "tblbankheadquartersandaddress" table using LEFT JOIN
, both have matching column values in tables.
You can use MySQL Command Line Client to fetch all records from left table and only matching record from right table where the join condition is satisfied. It will look like this: