Monday, September 23

Inner Join & Equi Join-SQL

Inner Join 

An Inner Join is a join in which the values in the columns are joined by using a comparison operator.
comparison operator such as 

  • = (equal to)
  • < (less than)
  • > (greater than)
  • <= (less than or equal to)
  • >= (greater than or equal to)
  • <> (not equal to)
  • != (not equal to)
  • !< (not less than)
  • !> (not greater than)
Example of Inner join;
Use AdventureWorksDW2008R2


select e.EmployeeKey,
c.CustomerKey,
e.FirstName,
c.LastName,
c.Gender,
e.Title,
e.BirthDate,
c.EmailAddress,
c.YearlyIncome from DimEmployee e inner join DimCustomer c 
on e.FirstName=c.FirstName and e.LastName=c.LastName ;

This query will display 24 rows of specified columns from both DimEmployee and DimCustomer based on firstname and lastname matching on a conditional operator.
As shown below:


Equi Join

An Equi Join is same as Inner Join, but the basic difference is that it selects all columns from both tables. so the query looks like this;

select * from DimEmployee e inner join DimCustomer c 
on e.FirstName=c.FirstName and e.LastName=c.LastName ;