SQL Right Join
August 31, 2019


As the name suggests the SQL right join displays all the records from the right side table and all the matching records from the left side table. Let’s take a look at the syntax. 

SELECT column/columns
FROM table_left RIGHT JOIN table_right
ON table_left.column= table_right.column;

As you can see in the syntax above, the query will show all the records from the table on the right side (table_right) and also the matched records form the table on the left side (table_left).

Let’s take a look at the example:

SELECT country.Region, countrylanguage.Language, country.Name, country.Code
FROM country
RIGHT JOIN countrylanguage ON country.Code=countrylanguage.CountryCode ORDER BY Code LIMIT 10;

It’s the same example form LEFT join article. The only difference is the RIGHT join keyword.

In the example above, I am selecting the columns Region, Name and Code from country table and Language from countrylanguage table. As I’ve discussed before the table on the right side will have it’s all records pulled up and displayed, which in this example, is countrylanguage table. Then the query watches out for the similar records in  both the tables and then displays those records from the tables.

If the records are exactly matching from all the columns requested then it will only display single entry otherwise there will be multiple lines of display. For example, let’s say the language is different for matching records for AFG country code. Then it will create a row with all the records form left column and then create one more row for the matching records with entries from the right table.

I’ve set the LIMIT 10 as both of tables have approx. 100 lines of records.


Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 2 How to zoom an element on hover using CSS? Mar 2 the box-sizing property in CSS Mar 2 WordPress: How to access first and random row values from a repeater field in ACF? Mar 1 The basics of CSS Box model Feb 27 WordPress: How to display slider repeater fields in ACF? Feb 26 Simple Page Hit Counter in PHP

You might also like these

PostgreSQL BETWEENPostgresWhat’s new in WordPress 5.5?WordPressHow to set the permissions on all files and folders in Mac?MiscThe SQL EXISTS OperatorSQL/MySQLWordPress: How to get field values in Advanced Custom Fields?WordPressEssential SQL Commands We Need to KnowSQL/MySQL