See how you stack up against top hiring criteria for the role in 2025.
Compare against 1000+ live job postings
Identify critical technical skill gaps
Get a personalized improvement roadmap
No signup required, takes less than 30 sec
Introduction
SQL JOIN is a crucial concept that allows you to combine data from multiple tables based on a related column. EQUI JOIN is a specific type of JOIN that uses the equality operator (=) to match the values in the related columns.
In this article, we'll talk about EQUI JOIN and its various components in detail, like its syntax, examples, and how it differs from other types of JOINs.
EQUI JOIN in SQL
EQUI JOIN is used when you want to combine rows from two or more tables based on a related column. It uses the equality operator (=) to compare the values in the specified columns. The basic syntax for an EQUI JOIN is as follows:
SELECT column1, column2, ...
FROM table1
JOIN table2 ON table1.column = table2.column;
In this syntax, "table1" and "table2" are the names of the tables you want to join, and "column" is the name of the related column in each table. The ON clause specifies the condition for joining the tables.
Examples
Let's consider two tables, "employees" and "departments", with the following structures:
SQL
SQL
CREATE TABLE employees ( employee_id NUMBER PRIMARY KEY, first_name VARCHAR2(50), last_name VARCHAR2(50), department_id NUMBER );
To retrieve the employee names along with their corresponding department names, you can use an EQUI JOIN like this:
SQL
SQL
SELECT employees.first_name || ' ' || employees.last_name AS name, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.department_id;
Output
This query will return a result set with two columns: "name" from the "employees" table and "department_name" from the "departments" table. The JOIN condition `employees.department_id = departments.department_id` ensures that only the rows with matching department IDs are combined.
Equi Join Using Three Tables
EQUI JOIN can also be used to join more than two tables. Let's add a third table, "salaries", with the following structure:
SQL
SQL
CREATE TABLE salaries ( employee_id NUMBER PRIMARY KEY, salary NUMBER );
Output
To retrieve the employee names, their department names, and their salaries, you can use an EQUI JOIN across all three tables:
SQL
SQL
SELECT employees.employee_id, employees.first_name, employees.last_name, departments.department_name, salaries.salary FROM employees JOIN departments ON employees.department_id = departments.department_id JOIN salaries ON employees.employee_id = salaries.employee_id;
Output
In this example, the "employees" table is joined with the "departments" table based on the "department_id" column, and then the result is further joined with the "salaries" table based on the "employee_id" column. The final result set will contain the employee names, department names, and their corresponding salaries.
Difference between Natural Join, Equi Join and Inner Join:
Natural Join
Equi Join
Inner Join
Automatically matches columns with the same name
Requires explicit specification of the columns to join
Can use any condition in the ON clause
No need to specify the join condition
Join condition is specified using the equality operator (=)
Combines rows that satisfy the join condition
Removes duplicate columns
Keeps all columns from both tables
Returns only matching rows
May not always produce the desired result
Provides more control over the join condition
Equivalent to Equi Join with additional flexibility
Suitable when tables have columns with the same name and data type
Suitable when columns have different names or when a specific condition is required
Suitable for most common join scenarios
Frequently Asked Questions
Can Equi Join be used with more than two tables?
Yes, Equi Join can be used to join multiple tables by specifying join conditions between each pair of tables.
Is Equi Join case-sensitive?
Equi Join is case-sensitive when comparing string values. If the column collation is case-insensitive, the join will be case-insensitive.
What happens if there are no matching rows in an Equi Join?
If there are no matching rows based on the join condition, those rows will be excluded from the result set.
Conclusion
In this article, we discussed Equi Join, a type of SQL JOIN that combines rows from multiple tables based on matching values in specified columns. We talked about the syntax of Equi Join & saw examples of joining two or more tables. We also discussed the differences between Natural Join, Equi Join & Inner Join. Equi Join provides a powerful way to retrieve related data from multiple tables, allowing for efficient querying & data analysis.
You can also practice coding questions commonly asked in interviews on Coding Ninjas Code360.