In SQL, the EQUI JOIN is used to combine rows from two or more tables based on a matching column between them. The term “EQUI” stands for equality, meaning that the columns being compared have the same values.
Syntax
The syntax for an EQUI JOIN is as follows:
SELECT columns
FROM table1
JOIN table2
ON table1.column = table2.column;
Where:
columns
are the columns you want to select from the resulting table.table1
andtable2
are the tables you want to join.column
is the column from each table that you want to match.
Example
Let’s consider two tables, “Customers” and “Orders”. The “Customers” table has columns for customer name, ID, and country, while the “Orders” table has columns for order ID, product, and customer ID. We want to join these two tables based on the common customer ID column.
To perform the EQUI JOIN, we can use the following query:
SELECT Customers.CustomerName, Orders.Product
FROM Customers
JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;
This query will return the customer name from the “Customers” table and the product from the “Orders” table, only for the matching customer IDs in both tables.
Conclusion
The EQUI JOIN is a useful tool in SQL for combining data from multiple tables based on the equality of specific columns. It allows us to retrieve correlated data and create meaningful relationships between tables. By understanding the syntax and usage of EQUI JOINs, you can effectively perform more complex queries and retrieve the desired information from your database.