Description

The SQL keyword RIGHT JOIN is used to join two tables, which returns the data as mentioned below.

  • The result set includes all the records from the right table.
  • For the matching records between the tables, the data for the columns coming from the left table is pulled from the left table.
  • For the non-matching records, a NULL value is used for the columns coming from the left table.

RIGHT JOIN

The below SQL fetches data from specific columns of the joined tables.

Run this on IDE

SELECT order_id, order_date, order_value, customer_name
FROM orders
RIGHT JOIN customers ON orders.customer_id = customers.customer_id;

RIGHT JOIN All Columns

The below SQL fetches data from all columns of the joined tables.

Run this on IDE

SELECT *
FROM orders
RIGHT JOIN customers ON orders.customer_id = customers.customer_id;

Related Links