MySQL INNER JOIN
MySQL INNER JOIN
In this tutorial, we will learn about MySQL INNER JOIN. A join that identifies combinations of matching rows from two tables is called as an inner join. There are two different types of syntax for inner joins:
- Using comma syntax(lists the tables to be joined separated by a comma)
- Using the INNER JOIN keyword
Let’s use the tables in the MySQL world database in the following examples.
Comma Join
https://www.testingdocs.com/mysql-comma-joins/
INNER JOIN Keyword
The INNER JOIN replaces the comma separator between the tables. The join row matching condition is now mentioned in the ON sub-clause. The INNER JOIN keyword is equivalent to the JOIN keyword and they can be used interchangeably.
Syntax
The general syntax of the statement is as follows:
SELECT <column_list>
FROM <table1> AS t1 INNER JOIN <table2> AS t2
ON <table_relationship_condition> ;
Example
mysql> SELECT c.Code, c.Name, cl.Language
-> FROM Country AS c INNER JOIN CountryLanguage AS cl
-> ON c.Code = cl.CountryCode
-> AND c.Continent=’North America’;
A table reference can be aliased using the AS clause.The clause is <table_name> AS <alias_name>. For example, Country AS c. We can refer the table column names with the table alias. c.Code to refer to the Code column in the Country table.
We can also use the WHERE clause to further narrow down the join query results.
USING()
If the name of the joined column is the same( i.e bearing the exact same name) in the both the joined tables, we can use the USING() clause instead of ON clause after the table names.
SELECT <column_list>
FROM <table1> AS t1 INNER JOIN <table2> AS t2
USING(<common_column_name>)
—
MySQL Tutorials
MySQL Tutorials on this website:
https://www.testingdocs.com/mysql-tutorials-for-beginners/
For more information on MySQL Database: