×

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 Show index

This query helps to access and retrieve table information. This syntax displays the required index or all indexes of the table. It also displays the index type as per the...

3 minutes read.

MySQL MONTHNAME() function

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

3 minutes read.

MySQL Character Length Function

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

2 minutes read.

MySQL EXPORT_SET() function

In this context, we will learn how we can use the MySQL EXPORT_SET() function with proper syntax and good examples. Introduction of MySQL EXPORT_SET() function This function returns a string and shows...

3 minutes read.

MySQL RIGHT() Function

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

3 minutes read.

MySQL Index

An index is a widely used method to access table information quickly. MySQL requires an index for operating table data stored in rows and columns. It's an entry point of...

3 minutes read.

MySQL FIND_IN_SET() function

In this context, we will learn how we can use the MySQL MOD() function with proper syntax and good examples. Introduction of MySQL MOD() function MySQL provides a built-in string function called...

4 minutes read.

MySQL Queries

MySQL Queries MySQL supports SQL queries in the MySQL interface. These queries help to interact data with the application. MySQL uses create database, user database, create a table, truncate table, and...

13 minutes read.

MySQL SUM function

The SUM() function displays the total addition of the table values. It supports the arithmetic operation of the column values. This function does not return a null value. Here, the...

5 minutes read.

MySQL Vs MongoDB

What is MongoDB? MongoDB is a distributed, open-source, cross-platform document-based database which was created to scale and develop applications simply. It was created as a NoSQL database by MongoDB Inc. MongoDB gets...

6 minutes read.

MySQL DELETE JOIN

Sometimes join becomes complicated and unwanted. In such cases, we can delete the unwanted joins in the tables. You can delete inner join, left join, right join as per requirement....

3 minutes read.

MySQL Stored Procedure

MySQL creates the "stored procedure" function to operate database information. You can use parameters, blocks, and statements to create a new procedure. The procedure requires a database table to use...

3 minutes read.

MySQL CURRENT_DATE() Function

In this context, we will learn how we can use the MySQL CURRENT_DATE() function to get the current date, and we will see in the two formats, such as strings...

2 minutes read.

MySQL HEX() function

In this context, we will learn how we can use the MySQL HEX() function with proper syntax and good examples. Introduction of MySQL HEX() function For returning an equivalent hexadecimal string value...

3 minutes read.

MySQL COUNT function

The count function returns the number of rows in the table. This function shows either the entire rows count or the required row count of the table. It determines the...

5 minutes read.

MySQL Database Introduction

MySQL - Database Introduction: The database plays an essential role in MySQL for storing and modifying the data. The database creates and keeps multiple tables. The database organizes and manipulates...

8 minutes read.

MySQL FROM_BASE64() function

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

2 minutes read.

MySQL LOG() function

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

3 minutes read.

MySQL INSERT() Function

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

2 minutes read.

MySQL POW() function

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

2 minutes read.