Site icon TestingDocs.com

MySQL Comma Joins

Overview

In this tutorial, we will learn MySQL Comma Joins. This syntax is one way to perform inner join. To combine data from two or more tables to find the detail of rows referenced by a foreign key, we can perform the join. One such way to do the join operation is to specify the list of tables with comma separator in the FORM clause of the SELECT statement. We can specify the relationship between the two tables using the WHERE clause.

Comma Join Syntax

In this syntax, we will specify a list of comma separated tables (that participate in the join) in the FROM clause of the SELECT statement. The WHERE clause is used to indicate the relationship between the tables.

The general comma join syntax of two tables is as follows:

SELECT <column_list>
FROM <table1>, <table2>
WHERE <table_relationship_conditions> ;

Example

Let’s consider Country and CountryLanguage tables in the world MySQL database in this example. Suppose that we want to find all the languages spoken in North America countries. This information cannot be found in just one table of the database.

We need to join the Country and the CountryLanguage tables in the world database. We have to extract the country names from the Country table and the languages from the CountryLanguage table.

 

mysql> SELECT Code, Name, Language
         -> FROM Country, CountryLanguage
         -> WHERE Code = CountryCode
         -> AND Continent=’North America’;

 

Notice the use of comma separator in the FROM clause used to join the tables.

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Exit mobile version