🚨 Time is Running Out: Reserve Your Spot in the Lucky Draw & Claim Rewards! START NOW

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;
DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
Udemy
Pros
  • Easy to navigate
  • No technical issues
  • Seems to care about its users
Main Features
  • Huge variety of courses
  • 30-day refund policy
  • Free certificates of completion

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;