0% found this document useful (0 votes)
12 views

Inner Join Example

The document discusses different types of SQL joins, including inner join, equi join, and natural join. An inner join returns rows that match between tables, using equality or other operators. An equi join only uses equality and is a type of inner join. A natural join implicitly joins on equally named columns between tables and only shows one column for each pair of columns joined.

Uploaded by

josearching
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Inner Join Example

The document discusses different types of SQL joins, including inner join, equi join, and natural join. An inner join returns rows that match between tables, using equality or other operators. An equi join only uses equality and is a type of inner join. A natural join implicitly joins on equally named columns between tables and only shows one column for each pair of columns joined.

Uploaded by

josearching
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL join clause is used to to retrieve data from two or more database tables.

In previous article, I have explained the Different Types of SQL Joins. In this article, I would explain the difference among inner join, equi join and natural join.

Inner Join
This is the most used join in the SQL. this join returns only those records/rows that match/exists in both the database tables.

Inner Join Example


1. SELECT * FROM tblEmp JOIN tblDept 2. ON tblEmp.DeptID = tblDept.DeptID;

Inner Join Result tblEmp.Name tblEmp.DeptID tblDept.Name tblDept.DeptID Ram 1 HR 1 Raju 2 IT 2 Soya 2 IT 2 Sam 3 ADMIN 3 In the join condition, you can also use other operators like <,>,<>.

Equi Join
Equi join is a special type of join in which we use only equality operator. Hence, when you make a query for join using equality operator then that join query comes under Equi join.

Equi Join Example

1. 2. 3. 4. 5.

SELECT * FROM tblEmp JOIN tblDept ON tblEmp.DeptID = tblDept.DeptID; --Using Caluse is supported in SQL Server --Oracle and MySQL Query SELECT * FROM tblEmp INNER JOIN tblDept USING(DeptID)

Equi Join Result tblEmp.Name tblEmp.DeptID tblDept.Name tblDept.DeptID Ram 1 HR 1 Raju 2 IT 2 Soya 2 IT 2 Sam 3 ADMIN 3 Note 1. Inner join can have equality (=) and other operators (like <,>,<>) in the join condition. 2. Equi join only have equality (=) operator in the join condition. 3. -Equi join can be an Inner join, Left Outer join, Right Outer join 4. The USING clause is not supported by SQL Server and Sybase. This clause is supported by Oracle and MySQL.

Natural Join
Natural join is a type of equi join which occurs implicitly by comparing all the same names columns in both tables. The join result have only one column for each pair of equally named columns.

Natural Join Example


1. --Run in Oracle and MySQL 2. SELECT * FROM tblEmp NATURAL JOIN tblDept

Natural Join Result DeptID tblEmp.Name tblDept.Name 1 Ram HR 2 Raju IT 2 Soya IT 3 Sam ADMIN In the above join result we have only one column "DeptID" for each pair of equally named columns. Note 1. In Natural join, you can't see what columns from both the tables will be used in the join. In Natural join, you might not get the desired result what you are expecting. 2. Natural join clause is not supported by SQL Server, it is supported by Oracle and MySQL. References: http://support.microsoft.com/ and http://en.wikipedia.org/

You might also like