1 May 2014

Inner Joins -- Sql server


An inner join is a join in which the values in the columns being joined are compared using a comparison operator.

In the ISO standard, inner joins can be specified in either the FROM or WHERE clause. This is the only type of join that ISO supports in the WHERE clause. Inner joins specified in the WHERE clauses are known as old-style inner joins.

the Equi-Joins always depend common column in the both tables 

Syntax:

select * from Table1.Column1,.... 
 inner join
Table2.Column1.... on Table1.Column1=Table2.Cloumn1

The following Transact-SQL query is an example of an inner join:

USE AdventureWorks2008R2;
GO
SELECT *
FROM Employee AS e
    INNER JOIN Department AS p
    ON e.EmpId = p. EmpId
ORDER BY p. EmpId

This inner join is known as an equi-join. It returns all the columns in both tables, and returns only the rows for which there is an equal value in the join column.

Consider two table such as employee table and department table

The Employee table consists of Employeeid,Employee Name Employee description and department id
The department table consists of department id ,department name and department location

Inner join for this above scenario is:

Select E.employeenumber,E.employeename,D.department name  from Employee E inner join Department D on E.department id  =D. department id 

1 comment: