JOINS
Everyone writes articles on the definitions of joins and examples of each.
Here are mine.
Join (simple join)
A simple join is when data in table1 and data in table2 match on the column being joined to.
Syntax Example:
Select
*
from
Employee a
Join
Employee_Salary b
on
a.EmployeeId = b.EmployeeId
Left Join
Get all of the data in table1 that has a like value in table2.
Select
*
from
Employee a
Left Join
Employee_Salary b
on
a.EmployeeId = b.EmployeeId
Left Outer Join
Get all of the data in table1 regardless if it has a match in table2.
Select
*
from
Employee a
Left outer Join
Employee_Salary b
on
a.EmployeeId = b.EmployeeId
Right Join
Get all of the data in table2 that has a like value in table1
Select
*
from
Employee a
Right Join
Employee_Salary b
on
a.EmployeeId = b.EmployeeId
Right Outer Join
Get all of the data in table2 regardless if it has a match in table1.
Select
*
from
Employee a
Right Outer Join
Employee_Salary b
on
a.EmployeeId = b.EmployeeId
Full outer join
Get all of the data in table1 and table2 regardless of matching data.
Select
*
from
Employee a
Full Outer Join
Employee_Salary b
on
a.EmployeeId = b.EmployeeId
Joins can make or break your query, one wrong join and you could end up with invalid data.
Tuesday, April 7, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment