Joins are used to combine the data from two tables and return specific rows of data from the tables.
A join can be either an inner join or an outer join, depending on what is expected in the result.
INNER JOIN:
Gets all matching rows in BOTH tables
LEFT JOIN:
Gets all rows from the left table along with matching rows from the right table
RIGHT JOIN:
Gets all rows from the right table along with matching rows from the left table
FULL JOIN:
Gets all rows provided there is a match in ONE of the tables
Let us say we have table X with data as below:
Let us say we have table Y with data as below:
Following will be the result of INNER JOIN :
Following will be the result of LEFT OUTER JOIN :
X |
Y |
1 |
null |
2 |
null |
13 |
13 |
14 |
14 |
Following will be the result of RIGHT OUTER JOIN :
X |
Y |
null |
11 |
null |
12 |
13 |
13 |
14 |
14 |
Following will be the result of FULL OUTER JOIN :
X |
Y |
1 |
null |
2 |
null |
13 |
13 |
14 |
14 |
null |
11 |
null |
12 |
0 Comment(s)