In MySQL, RIGHT JOIN
is used to fetch all records from RIGHT side table (tablename2) and only matching records from left side table (tablename1). It appears immediately after the FROM clause.
To fetch all records from RIGHT side table (tablename1) and only matching records from left 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.
RIGHT JOIN
, both have matching column values in tables :Note:
In the above example, we are fetching all "banks" fields value from "tblbankheadquartersandaddress" table and only matching record from "accountName" field from "tblbankdemataccountcharges" table using RIGHT JOIN
, both have matching column values in tables.
You can use MySQL Command Line Client to fetch all records from right table and only matching record from left side table where the join condition is satisfied. It will look like this: