Explanation of different types of Joins

JOINis used to combine the results of two tables. To perform a join, each of the tables must have at least one field which will be used to find matching records from the other table .The join type defines which records will go into the result set.Let’s take for example two tables:one table lists“regular”beverages, and another lists the”calorie-free beverages”.Each table has two fields: the beverage name and its product codeThe “code” field will be used to perform the record matchingLet’s join this table by the code field. Whereas the order of the joined tables makes sense in
some cases, we will consider the following statement:[Beverage] JOIN [Calorie-Free Beverage]ie [Beverage] is from the left of the join operator, and [Calorie-Free Beverage] is from the
right1)INNER JOIN:Result set will contain only those data where the criteria match
In our example we will get 3 records: 1 with COCACOLA and 2 with PEPSI codes2)OUTER JOIN:OUTER JOIN will always contain the results of INNER JOIN, however it can contain some records that have no matching record in other table.OUTER JOINs are divided to following subtypes:2.1)LEFT OUTER JOIN , or simply LEFT JOIN: The result will contain all records from the left
table. If no matching records were found in the right table, then its fields will contain the NULL values.In our example, we would get 4 records
In addition to INNER JOIN results, BUDWEISER will be listed, because it was in the left table2.2)RIGHT OUTER JOIN, or simply RIGHT JOIN:This type of join is the opposite of LEFT
JOIN; it will contain all records from the right table, and missing fields from the left table will contain NULL
If we have two tables A and B, then we can say that statement A LEFT JOIN B is equivalent to statement B RIGHT JOIN A
In our example, we will get 5 records.
In addition to INNER JOIN results, FRESCA and WATER records will be listed2.3)FULL OUTER JOIN:This type of join combines the results of LEFT and RIGHT joins.
All records from both tables will be part of the result set, whether the matching record exists in the other table or not.If no matching record was found then the corresponding result fields will have a NULL value.In our example, we will get 6 records

News Reporter

Leave a Reply

Your email address will not be published. Required fields are marked *