×

MySQL EQUI JOIN

An equijoin is an operation that combines multiple tables based on equality or matching column values in the associated tables. This operation links more than two tables based on a similar column or join. The equi join process uses the "WHERE" clause with equal (=) regular expression. In addition, this operation uses the "ON" clause to identify the table column and respective secondary table.

Rule of the equijoin

  • MySQL equi join does not need the same name columns for equal expression.
  • The multiple time's same columns can be displayed in the resultant result.
  • You can work on more than two tables for equi join operation.
  • The table does not display the null value in the column.
  • The table does not display the unmatched value of the tables.
  • The equal sign is necessary for comparison operation.
  • The equi join recommends ON and WHERE clause after JOIN statement.

Syntax

The "equi join" with the "WHERE" clause syntax shows below.

SELECT Column1 data type constraint,
Column2 data type constraint,
Column3 data type constraint,
FROM table1, table2, table2 WHERE table1.Column = table2.Column; 

The "equi join" with the "ON" operator syntax shows below.

SELECT Column1 data type constraint,
Column2 data type constraint,
FROM table1 JOIN table2 ON table1.Column = table2.Column; 

Examples

1) Example: the primary equijoin example shows below.

Execute the below query to understand MySQL equi join. This join requires more than one table to link with each other. Here, you can use the equal sign for the equi join operation.

mysql> SELECT d.department_name, d.department_id, 
s.subject_name, s.subject_id
FROM department AS d, subject AS s
WHERE d.department_id = s.subject_id;

OUTPUT

EQUI JOIN

The above image shows department and subject table's similar information. Here, the department_id column and subject_id column have the same information. The output displays four columns of the table using equi join.

2) Example: the equi join with multiple tables' example shows below.

Execute the below query for the equi join. Here, you can use an equal sign with the WHERE clause for joining tables using equijoin operation.

mysql> SELECT d.department_name, d.department_id, 
s.subject_name, s.subject_id, m.chapter, m.level
FROM department AS d, subject AS s, mysql_tutorial AS m
WHERE d.department_id = s.subject_id = m.index;

OUTPUT

EQUI JOIN

The above image shows department, subject, and mysql_tutorial table's similar information. Here, the department_id column, subject_id column, index column has the same information. The output displays six columns using equi join. The index column does not include in the output.

3) Example: the equi join with the "order by" clause example shows below.

Execute the below query for the equi join. This join requires more than one table to interconnect with each other. Here, you can use an equal sign with WHERE clauses for the equi join operation.

mysql> SELECT d.department_name, d.department_id, 
s.subject_name, s.subject_id, m.chapter, m.level
FROM department AS d, subject AS s, mysql_tutorial AS m
WHERE d.department_id = s.subject_id = m.index
ORDER BY department_id DESC;

OUTPUT

EQUI JOIN

The above image shows department, subject, and mysql_tutorial table's similar information. Here, the department_id column, subject_id column, index column has the same information. The output displays six columns of the table using equi join. The index column does not include in the output. The table data shows in a descending order using the "ORDER BY" clause.

4) Example: the equi join with "group by" clause example shows below.

Execute the below query to the MySQL equi join. This join requires more than one table to link with each other.

mysql> SELECT d.department_name, d.department_id, 
s.subject_name, s.subject_id, m.chapter, m.level
FROM department AS d, subject AS s, mysql_tutorial AS m
WHERE d.department_id = s.subject_id = m.index
GROUP BY subject_id;

OUTPUT

EQUI JOIN

The above image shows department, subject, and mysql_tutorial table's similar information. Here, the department_id column, subject_id column, index column has the same information. The output displays six columns of the table using equi join. This query uses the "GROUP BY" clause for grouping columns.

5) Example: the primary equi join example shows below.

Execute the below query for the equi join. This join requires more than one table to link with each other.

mysql> SELECT d.department_name, d.department_id, 
s.subject_name, s.subject_id
FROM department AS d JOIN subject AS s
ON d.department_id = s.subject_id;

OUTPUT

EQUI JOIN

The above image shows department and subject table's similar information. Here, the department_id column and subject_id column have the same information. The output displays four columns of the table using equi join. The ON clause works with equi join to show the same data.

6) Example: the equi join with multiple tables' example shows below.

Execute the below query for the equi join. Here, are using equal sign with ON clauses for equi join operation.

mysql> SELECT d.department_name, d.department_id, 
s.subject_name, s.subject_id, m.chapter, m.level
FROM department AS d JOIN subject AS s JOIN mysql_tutorial AS m
ON d.department_id = s.subject_id = m.index;

OUTPUT

EQUI JOIN

The above image shows department, subject, and mysql_tutorial table's similar information. Here, the department_id column, subject_id column, index column has the same information. The output displays six columns of the table using equi join. The ON clause works as an equi join to show the same data.

7) Example

Execute the below query for the equi join. Here, you can use the equal sign with the ON clause for the equi join operation.

mysql> SELECT d.department_name, d.department_id, 
s.subject_name, s.subject_id, m.chapter, m.level
FROM department AS d JOIN subject AS s JOIN mysql_tutorial AS m
ON d.department_id = s.subject_id = m.index
ORDER BY department_id DESC;

OUTPUT

EQUI JOIN

The above image shows department, subject, and mysql_tutorial table's similar information. Here, the department_id column, subject_id column, index column has the same information. The output displays six columns in descending order.

8) Example:

The below query uses the equal sign with the ON clause for the equi join operation.

mysql> SELECT d.department_name, d.department_id, 
s.subject_name, s.subject_id
FROM department AS d JOIN subject AS s 
ON d.department_id = s.subject_id 
GROUP BY subject_id;

OUTPUT

EQUI JOIN

The above image shows department, subject, and mysql_tutorial table's similar information. Here, the department_id column, subject_id column, index column has the same information. The output displays six columns of the table using equi join. The ON clause works as equijoin to show the same data. This query uses the "GROUP BY" clause for grouping columns.


Related Topics

MySQL EQUI JOIN

An equijoin is an operation that combines multiple tables based on equality or matching column values in the associated tables. This operation links more than two tables based on a...

5 minutes read.

MySQL Full text index

Full text index The full-text index in the table isused to search the full text of the data. This index assigns to the table using a "FULLTEXT" keyword. First, the table...

3 minutes read.

MySQL vs Oracle

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL GREATEST function

This statement displays the greatest values of the table. The GREATEST function returns a null value when the table contains a null value. The GREATEST function needs a minimum of...

2 minutes read.

MySQL LOAD_FILE() function

In this context, we will learn how we can use the MySQL LOAD_FILE() function with proper syntax and good examples. Introduction of MySQL LOAD_FILE() function The LOAD_FILE() function in MySQL reads a...

3 minutes read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 minutes read.

MySQL INSTR() Function

In this context, we will learn how we can use the MySQL INSTR() function with proper syntax and good examples. Introduction of MySQL INSTR() function This function in MySQL returns the location...

4 minutes read.

MySQL NOW() function

In this context, we will learn how we can use the MySQL NOW() function with proper syntax and good examples. Introduction of MySQL NOW() function Basically, in MySQL, this function is used...

2 minutes read.

MySQL Error 1046 - No Database Selected

What is MySQL? MySQL is a Relational Database Management System (RDBMS). SQL in MySQL is the abbreviation of "Structured Query Language", which Oracle developed it in 1995. It is one of...

1 minute read.

MySQL UPDATE JOIN

The UPDATE JOIN is a MySQL statement used to perform cross-table updates that means we can update one table using another table with the JOIN clause condition. The "update join"...

5 minutes read.

MySQL QUARTER() function

In this context, we will learn how we can use the MySQL QUARTER() function with proper syntax and good examples. Introduction of MySQL QUARTER() function The QUARTER() function in MySQL returns the...

3 minutes read.

MySQL: Entity-Relationship Model

Entity-Relationship Model Entity-Relationship model or E R model is used to create a relationship between different attributes or entities. It describes the structure of the database with the help of the...

5 minutes read.

MySQL Advance function

The advance function operates numerical values, string values, and data types.  The advance function converts, displays, and compares given values as per requirement. Here, you find out database, table, and...

4 minutes read.

MySQL SOUNDEX() function

In this context, we will learn how we can use the MySQL SOUNDEX() function with proper syntax and good examples. Introduction of MySQL SOUNDEX() function SOUNDEX() function in MySQL is used to...

3 minutes read.

MySQL Join

The relational database system needs to interconnect multiple tables with each other. MySQL is a popular and easy data management system to connect multiple tables. The foreign key is used...

5 minutes read.

MySQL Clauses

MySQL Clauses MySQL system clauses are keywords or statements to handle information. It helps to operate a group of the data and apply it to require conditions. The clauses apply conditions...

16 minutes read.

MySQL LN() function

In this context, we will learn how we can use the MySQL LN() function with proper syntax and good examples. Introduction of MySQL LN() function For evaluation of the natural logarithm of...

2 minutes read.

MySQL DATE_FORMAT() function

In this context, we will learn how we can use the MySQL DATE_FORMAT() function with proper syntax and good examples. Introduction of MySQL DATE_FORMAT() function DATE_FORMAT() function in MySQL is used to...

3 minutes read.

MySQL CEIL() function

In this context, we will learn how we can use the MySQL CEIL () function with proper syntax and good examples. Introduction of MySQL CEIL() function Input is taken by the CEIL()...

3 minutes read.

MySQL SELF JOIN

This join links table with itself. The inner join, a self join, a right join, and a cross join are connected with two or more two tables. But, the "self...

4 minutes read.