Yogesh Chauhan's Blog

SQL Inner Join

in SQL/MySQL on August 24, 2019


We use JOIN clause in SQL to combine rows from two or more tables based on a similar column between those tables.


SELECT column/columns
FROM table1
ON table1.column = table2.column;

Basically we are selecting columns from table 1 and 2 and joining them where the records are matching. Let’s look at the example,

SELECT country.Region, countrylanguage.Language, country.Name
FROM country
INNER JOIN countrylanguage ON country.Code=countrylanguage.CountryCode LIMIT 20;

In the example above, I am selecting Region column from country table, Language column form countrylanguage table and Name column for country table. Now the inner join has been performed on countrylanguage table. In the case of INNER JOIN, the order of the the tables doesn’t matter as it’s going to select the matching values only. Now we have to apply the condition to make sure we are getting the data for matching values only.

Now in the countrylanguage the name of the country code column is CountryCode but in the country table it’s just Code. So we have to be careful while comparing those two columns or the query won’t work. So at the end the second condition is c.CountryCode=b.Code

To show only limited number of rows I have used the LIMIT clause. You can see the results in the DEMO. For all the matching values we have Region, Language and Name data.

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS? #Jan 8 How to Install Xcode Command Line Tools on MacOS?
You might also like these
JavaScript Data Types and Data Structures Things to RememberJavaScriptHow to Sort (Shuffle) an Array in Random Order in JavaScript?JavaScriptSolution to Could not cast value of type ‘NSTaggedPointerString’ to ‘NSNumber’SwiftWhat’s new in WordPress 5.5?WordPressHow to create a simple tab interaction using CSS?CSSWhat is Zdog?Miscellaneous