NOTE All of this can be found on Wikipedia: Join (SQL) .
There are three types of OUTER connections:
- LEFT OUTER JOIN
- CORRECT ENTRY TOGETHER
- FULL BUILT-IN WORK
The OUTER keyword is optional in all implementations that follow the standard, so FULL JOIN matches FULL OUTER JOIN. (I left the word OUTER from SQL in the rest of this answer.)
Let's see what everyone does.
Consider the following two sets of input data:
Set "A" Set "B" AA BB
Note that in there are some elements that are not in B, and vice versa.
Now, if we write an SQL statement like this, using a LEFT join:
SELECT * FROM A LEFT JOIN B ON AA = BB
You will get the following result (empty holes are actually NULL ):
AA BB -------- -------- Item 1 Item 2 Item 3 Item 3 Item 4 Item 4
Note that you will get all rows from AA, or rather, all rows from the left side of the join clause.
If you switch to using RIGHT join:
SELECT * FROM A RIGHT JOIN B ON AA = BB AA BB
Note that you get all the rows from the right side of the join condition.
However, if you want all the lines of both, you will use a FULL join:
SELECT * FROM A FULL JOIN B ON AA = BB AA BB
As pointed out in a comment, let me fill out other connection methods.
With INNER join:
SELECT * FROM A INNER JOIN B ON AA = BB AA BB
With an INNER join, we get only rows that actually match, without holes due to the join.
The CROSS join creates a Cartesian product by matching each row from the first set with each row from the second set:
SELECT * FROM A CROSS JOIN B AA BB -------- -------- Item 1 Item 3 ^ Item 1 Item 4 +--- first item from A, repeated for all items of B Item 1 Item 5 | Item 1 Item 6 v Item 2 Item 3 ^ Item 2 Item 4 +--- second item from A, repeated for all items of B Item 2 Item 5 | Item 2 Item 6 v Item 3 Item 3 ... and so on Item 3 Item 4 Item 3 Item 5 Item 3 Item 6 Item 4 Item 3 Item 4 Item 4 Item 4 Item 5 Item 4 Item 6
Also note that we will not indicate which columns should match, as there is no corresponding match.
Finally, NATURAL join, in this syntax we do not specify which columns correspond, but correspond to the column names. In our far-fetched example, the column names do not match, but let's say for this specific example that the column names in both tables were XX, then we get the following result:
SELECT * FROM A NATURAL JOIN B +
As you can see, you get the same thing as INNER join, but you should not enter the matching part of the join clause.