Code has been added to clipboard!

Matching Data From Multiple Tables with SQL RIGHT JOIN

Reading time 1 min
Published Aug 9, 2017
Updated Oct 10, 2019

SQL RIGHT JOIN Keyword: Main Tips

  • This keyword brings back every row out of the right table into the same rows on the left table.
  • The value contained in the first table is NULL where the rows were not matched.

Syntax of SQL RIGHT JOIN

Example
SELECT column_name(s)
FROM tbl1
RIGHT JOIN tbl2 ON tbl1.column_name = tbl2.column_name;

Demo Database

The "Orders" database table below:

ID Customer_ID Employee_ID
20408 2 7
20409 2 5
85471 1 3
75864 5 8

The "Employees" database table below:

ID Last_Name First_Name Birthdate Photos Note
1 Bob Bobby 11/18/1965 EmpID1.pic Cars are an important thing in my life...
2 Bill Billy 5/14/1954 EmpID2.pic Books are an important thing in my life...
3 Ben Benny 4/25/1967 EmpID3.pic Music is an important thing in my life...

SQL RIGHT JOIN: Example

The code example below will bring back every data record from employees with all the placed orders:

Example
SELECT Customer_orders.ID, Employees.Last_name, Employees.First_name
FROM Customer_orders
RIGHT JOIN Employees ON Customer_orders.employee_id = Employees.ID
ORDER BY Customer_orders.ID;
Learn SQL
Introduction
Syntax
Data Types
Server Data Types
Commands
Commands List
Wildcards
Constraints
Aggregate Functions
Date Functions
Date Format
Injection
SQL Server Hosting
Views
Auto-incrementation
SQL Operators
AS
AND & OR
IN
BETWEEN
WHERE
GROUP BY
HAVING
ORDER BY
LIKE
NOT
NOT EQUAL
UNION
NULL
NOT NULL
DEFAULT
UNIQUE
FOREIGN KEY
PRIMARY KEY
CHECK
Indexes
ALTER TABLE
CREATE DATABASE
CREATE TABLE
DELETE
DROP
INSERT INTO SELECT
INSERT INTO
SELECT
SELECT DISTINCT
SELECT INTO
SELECT TOP
UPDATE
FULL OUTER JOIN
INNER JOIN
JOIN
LEFT JOIN
RIGHT JOIN
AVG()
COUNT
FIRST
LAST
MAX
MIN()
SUM()
LEN
UCASE
MID
NOW
ROUND
FORMAT
LOWER
CONVERT
ISNULL