Skip to content
  • AI
  • Github

Scratch that

Bite sized bits

  • AI
  • Github
  • ⤫

Right Join – SQL

Posted by Posted on
0

A RIGHT JOIN (also called a RIGHT OUTER JOIN) is similar to a LEFT JOIN, but it returns all rows from the right table and any matching rows from the left table. If there is no match, NULL values are returned for the left table’s columns.

Here is the syntax for a RIGHT JOIN in SQL:

 

Copy Code Copied Use a different Browser

SELECT column1, column2, ...
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;

Here’s an example that joins the “customers” and “orders” tables on the “customer_id” column:

Copy Code Copied Use a different Browser

SELECT customers.name, orders.order_date
FROM customers
RIGHT JOIN orders
ON customers.customer_id = orders.customer_id;

his will return all rows from the “orders” table, along with any matching rows from the “customers” table. If an order was placed by a customer who is not in the “customers” table, NULL values will be returned for the “customers.name” column.

Note: Some databases do not support RIGHT JOINs. In those cases, you can achieve the same result using a LEFT JOIN with the tables reversed. For example:

Copy Code Copied Use a different Browser

ELECT customers.name, orders.order_date
FROM orders
LEFT JOIN customers
ON orders.customer_id = customers.customer_id;

Categories: Algorithms

Post navigation

Previous Previous post: Left join – SQL
snow covered mountains
Next Next post: Neural Networks
  • Algorithms
  • Front-end
  • Javascript
  • Philosophy
  • Project Management
  • Psychology
  • Science
  • Technology
  • Uncategorized
Copyright © 2025 - Scratch that // By - Deepak Anandrao