RIGHT JOIN
returns all matching records from the right table combined with the left table. Even if there are no match records in the left table, the RIGHT JOIN
will still return a row in the result, but with NULL
in each column from the left table.
RIGHT JOIN
clause.SELECT column_1, column_2...
defines the columns from both tables where we want to display data.FROM table_1
, defines the left table with table_1 in the FORM clause.RIGHT JOIN table_2
defines the right table with table_2 in the RIGHT JOIN condition.ON table_1.matching_field = table2.matching_field
sets the join condition after the ON keyword with the matching field between the two tables.RIGHT JOIN
query as follows:customer_name
and order_amount
columns as defined in the SELECT
clause.NULL
value from the left table (customer).181893
matches the customer: Ellie.
181894
matches the customer: Ellie
.181891
matches the customer: James
.181899
matches the customer: James
.181892
matches the customer: Mary
.181897
doesn’t match with any customer. Thus the customer_name column is filled with: null
.RIGHT JOIN
: