SQL EQUI JOIN performs a JOIN against equality or matching column(s) values of the associated tables. An equal sign (=) is used as comparison operator in the where clause to refer equality. You may also perform EQUI JOIN by using JOIN keyword followed by ON keyword and then specifying names of the columns along with their associated tables to check equality. Pictorial presentation of SQL Equi Join: Syntax: or Example: Here is an example of Equi Join in SQL. Sample table: agents Sample table: customer To get agent name column from agents table and cust name and cust city columns from customer table after joining said two tables with the following condition - 1. working area of agents and customer city of customer table must be same, the following SQL statement can be used: SQL Code: Output: An equijoin is a join with a join condition containing an equality operator. An equijoin returns only the rows that have equivalent values for the specified columns.
What is the difference between Equi Join and Inner Join in SQL?
An inner join is a join of two or more tables that returns only those rows (compared using a comparison operator) that satisfy the join condition.
Pictorial presentation : SQL Equi Join Vs. SQL Inner Join
Key points to remember
Click on the following to get the slides presentation -
Practice SQL Exercises
Want to improve the above article? Contribute your Notes/Comments/Examples through Disqus.
Previous: Introduction
Next: SQL NON EQUI JOIN
MySQL Error: : 'Access denied for user 'root'@'localhost'
- Open and edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distribution.
- Add skip-grant-tables under [mysqld]
- Restart MySQL
- You should be able to log in to MySQL now using the below command mysql -u root -p
- Run mysql> flush privileges;
- Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
- Go back to /etc/my.cnf and remove/comment skip-grant-tables
- Restart MySQL
- Now you will be able to login with the new password mysql -u root -p
Ref: //bit.ly/2PvZubo
We have already learned that an EQUI JOIN performs a JOIN against equality or matching column(s) values of the associated tables and an equal sign (=) is used as comparison operator in the where clause to refer equality. The SQL NATURAL JOIN is a type of EQUI JOIN and is structured in such a way that, columns with the same name of associated tables will appear once only. Pictorial presentation of the above SQL Natural Join:
Natural Join: Guidelines
- The associated tables have one or more pairs of identically named columns. - The columns must be the same data type.
- Don’t use ON clause in a natural join.
Syntax:
SELECT * FROM table1 NATURAL JOIN table2;Example:
Here is an example of SQL natural join between tow tables:
Sample table: foods
Sample table: company
To get all the unique columns from foods and company tables, the following SQL statement can be used:
SQL Code:
SELECT * FROM foods NATURAL JOIN company;Output:
COMPANY_ID ITEM_ID ITEM_NAME ITEM_UNIT COMPANY_NAME COMPANY_CITY ---------- ---------- ------------------------- ---------- ------------------------- -------------- 16 1 Chex Mix Pcs Akas Foods Delhi 15 6 Cheez-It Pcs Jack Hill Ltd London 15 2 BN Biscuit Pcs Jack Hill Ltd London 17 3 Mighty Munch Pcs Foodies. London 15 4 Pot Rice Pcs Jack Hill Ltd London 18 5 Jaffa Cakes Pcs Order All BostonDifference between natural join and inner join
There is one significant difference between INNER JOIN and NATURAL JOIN is the number of columns returned. See the following example on company table and foods table :
SQL Code:
SELECT * FROM company;Output:
SQL Code:
SELECT * FROM foods;Output:
ITEM_ID ITEM_NAME ITEM_UNIT COMPANY_ID ---------- ------------------------- ---------- ---------- 1 Chex Mix Pcs 16 6 Cheez-It Pcs 15 2 BN Biscuit Pcs 15 3 Mighty Munch Pcs 17 4 Pot Rice Pcs 15 5 Jaffa Cakes Pcs 18 7 Salt n Shake PcsThe INNER JOIN of company and foods on company_id will return :
SQL Code:
SELECT * FROM company INNER JOIN foods ON company.company_id = foods.company_id;Output:
COMPANY_ID COMPANY_NAME COMPANY_CITY ITEM_ID ITEM_NAME ITEM_UNIT COMPANY_ID ---------- --------------- --------------- ---------- --------------- ---------- ---------- 16 Akas Foods Delhi 1 Chex Mix Pcs 16 15 Jack Hill Ltd London 6 Cheez-It Pcs 15 15 Jack Hill Ltd London 2 BN Biscuit Pcs 15 17 Foodies. London 3 Mighty Munch Pcs 17 15 Jack Hill Ltd London 4 Pot Rice Pcs 15 18 Order All Boston 5 Jaffa Cakes Pcs 18SQL Code:
SELECT * FROM company NATURAL JOIN foods;Output:
COMPANY_ID COMPANY_NAME COMPANY_CITY ITEM_ID ITEM_NAME ITEM_UNIT ---------- --------------- --------------- ---------- --------------- ---------- 16 Akas Foods Delhi 1 Chex Mix Pcs 15 Jack Hill Ltd London 6 Cheez-It Pcs 15 Jack Hill Ltd London 2 BN Biscuit Pcs 17 Foodies. London 3 Mighty Munch Pcs 15 Jack Hill Ltd London 4 Pot Rice Pcs 18 Order All Boston 5 Jaffa Cakes PcsNATURAL JOINS: Relational Databases
- Oracle NATURAL JOIN
- MySQL NATURAL JOIN
- SQLite NATURAL JOIN
Key points to remember
Click on the following to get the slides presentation -
Practice SQL Exercises
Want to improve the above article? Contribute your Notes/Comments/Examples through Disqus.
Previous: SQL INNER JOIN
Next: SQL CROSS JOIN
MySQL Error: : 'Access denied for user 'root'@'localhost'
- Open and edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distribution.
- Add skip-grant-tables under [mysqld]
- Restart MySQL
- You should be able to log in to MySQL now using the below command mysql -u root -p
- Run mysql> flush privileges;
- Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
- Go back to /etc/my.cnf and remove/comment skip-grant-tables
- Restart MySQL
- Now you will be able to login with the new password mysql -u root -p
Ref: //bit.ly/2PvZubo