Você está na página 1de 9

12/2/2016 SQL Equi join ­ w3resource

w3resource

SQL Equi Join
Last update on November 08 2016 05:07:45 (UTC/GMT +8 hours)

 

What is Equi Join in SQL?
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.

Syntax

SELECT column_list  
FROM table1, table2.... 
WHERE table1.column_name = 
table2.column_name;  

or

SELECT * 
FROM table1  
JOIN table2 
[ON (join_condition)] 

Pictorial representation :

http://www.w3resource.com/sql/joins/perform­an­equi­join.php 1/9
12/2/2016 SQL Equi join ­ w3resource

Example
Here is an example of Equi Join in SQL.

Sample table : agents

http://www.w3resource.com/sql/joins/perform­an­equi­join.php 2/9
12/2/2016 SQL Equi join ­ w3resource

+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+
| AGENT_CODE | AGENT_NAME           | WORKING_AREA       | COMMISSION | PHONE_NO        | COUNTRY |
+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+
| A007       | Ramasundar           | Bangalore          |       0.15 | 077‐25814763    |         |
| A003       | Alex                 | London             |       0.13 | 075‐12458969    |         |
| A008       | Alford               | New York           |       0.12 | 044‐25874365    |         |
| A011       | Ravi Kumar           | Bangalore          |       0.15 | 077‐45625874    |         |
| A010       | Santakumar           | Chennai            |       0.14 | 007‐22388644    |         |
| A012       | Lucida               | San Jose           |       0.12 | 044‐52981425    |         |

Sample table : customer

+‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐
|CUST_CODE  | CUST_NAME   | CUST_CITY   | WORKING_AREA | CUST_COUNTRY | GRADE | OPENING_AMT | RECEIVE_AMT
+‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐
| C00013    | Holmes      | London      | London       | UK           |     2 |     6000.00 |     5000.00
| C00001    | Micheal     | New York    | New York     | USA          |     2 |     3000.00 |     5000.00
| C00020    | Albert      | New York    | New York     | USA          |     3 |     5000.00 |     7000.00
| C00025    | Ravindran   | Bangalore   | Bangalore    | India        |     2 |     5000.00 |     7000.00
| C00024    | Cook        | London      | London       | UK           |     2 |     4000.00 |     9000.00
| C00015    | Stuart      | London      | London       | UK           |     1 |     6000.00 |     8000.00

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 :

view plain copy to clipboard print ?

01.  SELECT agents.agent_name,customer.cust_name,  
02.  customer.cust_city  
03.  FROM agents,customer  
04.  WHERE agents.working_area=customer.cust_city;  

Output

http://www.w3resource.com/sql/joins/perform­an­equi­join.php 3/9
12/2/2016 SQL Equi join ­ w3resource

AGENT_NAME                               CUST_NAME                                CUST_CITY
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ ­­­­­­­­­­­­
Ravi Kumar                               Ravindran                                Bangalore
Ramasundar                               Ravindran                                Bangalore
Subbarao                                 Ravindran                                Bangalore
Ravi Kumar                               Srinivas                                 Bangalore
Ramasundar                               Srinivas                                 Bangalore
Subbarao                                 Srinivas                                 Bangalore
Ravi Kumar                               Rangarappa                               Bangalore
Ramasundar                               Rangarappa                               Bangalore
Subbarao                                 Rangarappa                               Bangalore
Ravi Kumar                               Venkatpati                               Bangalore
Ramasundar                               Venkatpati                               Bangalore
Subbarao                                 Venkatpati                               Bangalore
Anderson                                 Fleming                                  Brisban
Anderson                                 Jacks                                    Brisban
Anderson                                 Winston                                  Brisban
Santakumar                               Yearannaidu                              Chennai
...........
...........

What is the difference between Equi Join and Inner Join in SQL?
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.
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 representation : EQUI JOIN Vs. INNER JOIN

http://www.w3resource.com/sql/joins/perform­an­equi­join.php 4/9
12/2/2016 SQL Equi join ­ w3resource

Key points to remember
Click on the following to get the slides presentation ­

         

http://www.w3resource.com/sql/joins/perform­an­equi­join.php 5/9
12/2/2016 SQL Equi join ­ w3resource

 
Is this content useful for you?

Yes No

10 Comments w3resource 
1 Login

  Recommend  3 ⤤ Share Sort by Newest

Join the discussion…

fede • 10 months ago
select * from
table_a join table_b
USING(id)

is this code similar to your code??

EQUI JOIN is an special case of INNER JOIN??

Thanks
△   ▽ • Reply • Share ›

ankit dubey • a year ago
you peoples have given the same examples for both inner and equi joins please give me some key
differences. 
Thanks...
△   ▽ • Reply • Share ›
http://www.w3resource.com/sql/joins/perform­an­equi­join.php 6/9
12/2/2016 SQL Equi join ­ w3resource
△   ▽ • Reply • Share ›

evets > ankit dubey • a year ago
Also for your information, here is a comparison chart of an apple vs. apple:
http://s13.postimg.org/gluj1g0...
△   ▽ • Reply • Share ›

w3resource  Mod   > ankit dubey •  a year ago

Actually there is no difference between EQUI JOIN and INNER, because INNER JOIN is a
part of EQUI JOIN. Look the example we have attached for your better understand.
△   ▽ • Reply • Share ›

prince jain • 3 years ago
thanks ..
please specify differance between equi join and inner join.. ..with example.. 
1 △   ▽ • Reply • Share ›

Ajith • 4 years ago
thanku..
△   ▽ • Reply • Share ›

praveen acharya • 5 years ago
Is there ANY Difference in between natural join. 
mail me plsmrpkacharya@gmail.com
△   ▽ • Reply • Share ›

w3resource  Mod   > praveen acharya  •  5 years ago

If you look at the syntax of EQUI JOIN and NATURAL JOIN, you would find that in
NATURAL JOIN you don't need to specify column names, you specify tables instead,
where as, in EQUI JOIN, you specify column names.
△   ▽ • Reply • Share ›

Smehanwal • 5 years ago
where is join­on
△   ▽ • Reply • Share ›

w3resource  Mod   > Smehanwal  •  5 years ago

We have showed JOIN ON in the syntax. But yes, an example with JOIN ON would be
more useful. We will do that soon. Thanks.
△   ▽ • Reply • Share ›

✉ Subscribe d Add Disqus to your site Add Disqus Add 🔒 Privacy

http://www.w3resource.com/sql/joins/perform­an­equi­join.php 7/9
12/2/2016 SQL Equi join ­ w3resource

©w3resource 2011­15
Privacy policy
About
Contact
Feedback
Advertise

http://www.w3resource.com/sql/joins/perform­an­equi­join.php 8/9
12/2/2016 SQL Equi join ­ w3resource

http://www.w3resource.com/sql/joins/perform­an­equi­join.php 9/9

Você também pode gostar