Friday, February 25, 2011

Left and Right Outer Joins...Awesome

Outer joins return all rows from one of the tables in the FROM clause, this is as long as those rows meet any WHERE search conditions. All rows are retrieved from the left table referenced with a left outer join, and all rows from the right table referenced in a right outer join.

Below is a "Left Outer Join" example that will be explained in extraneousness detail after the code.\/\/\/
 SELECT *  
 FROM Employee   
   LEFT OUTER JOIN Jobs  
   ON Employee.PayGrade = Jobs.PayGrade  
Since this is a LEFT OUTER JOIN so it will show all the "Employee" records, and all the "Jobs" records that have a "PayGrade" that is also in the same as the "Employee" "PayGrade".

Below is a "Right Outer Join" example that will be explained below the code.\/\/\/
 SELECT *  
 FROM Employee   
   RIGHT OUTER JOIN Jobs  
   ON Employee.PayGrade = Jobs.PayGrade    
A RIGHT OUTER JOIN is almost exactly the same as a LEFT OUTER JOIN, but instead of having all the records from the first table stated, "Employee", it will have all the records in "Jobs" instead, showing the "Employee" records with the same "PayGrade" of "Jobs".

More To Come, CA.

No comments:

Post a Comment