SQL Joins

A-Z of Mircrosoft SQL

Main Page Introduction SSMS Acronym's used in SQL SQL Commands SQL Functions SQL Store Procedures SQL Views SQL Triggers SQL Operators SQL - Adding Comments SQL Alias SQL Joins SQL - Building Basic Scripts SQL - Execution Plan Questions or Suggestions
H1B Jobs- Visual Reports

SQL Examples

Arithmetic Operators Comparision Operators Logical Operators Bitwise Operators String Functions Date Functions Numeric Functions


SQL Joins

In a Relational Databases (RDBMS) joins are a important part of the game. For example - we cannot store all the data in one table only, which will be a very bad structure. Hence data is stored in multiple tables and we can use joins to bring them together

There are FOUR types of JOINS , please see examples for each of them below.

Venn Diagram to Understand the Joins

Data which is returned is represented in color Green

For Examples we will be Joining two tables from Adventurework2012 databases, created for this purpose

LEFT TABLE :: [AdventureWorks2012].[Person].[Person_Temp] - 10000 records

RIGHT TABLE ::[AdventureWorks2012].[Person].[Password_Temp]- 15000 records

[INNER] JOIN

This join returns data if the records are in both the tables, I.e. if a person has data in Table A and Table B

This returns only 10000 records

SQL Inner join

LEFT [OUTER] JOIN

This join returns data for all persons in the Left table- which is the from table, I.e. if a person has data in Table A , irrespective of Table B

This returns only 10000 records

SQL Left join

RIGHT [OUTER] JOIN

This join returns data for all persons in the Right table- which is the JOIN table, I.e. if a person has data in Table B , irrespective of Table A

This returns 15000 records

SQL Right join

FULL [OUTER] JOIN

This join returns data for all persons in the BOTH tables I.e. if a person has data in Table B or in Table A

This returns 15000 records

SQL FullOuter join

Next Stop: SQL - Building Basic Scripts