For SQL joins, learning may be a bit confusing. We know that the join syntax for SQL has a lot of inner, outer, left, and sometimes it's not very clear what the result set looks like for a select. There is an article on Coding horror (it is not clear why Coding horror was also the wall) through the Venturi diagram Venn diagrams explained the join of SQL. I feel clear and understandable, turn around.
Suppose we have two tables, table A is the one on the left and table B is the one on the right. What is the Venetian Macao?
Each of them has four records, of which two records are the same, as follows:
Let's look at the results of different joins.
1 |
SELECT * FROM TableA INNER JOIN TableB |
2 |
ON TableA. name = TableB. name |
Inner Join The resulting set of results is the intersection of a and B. |
|
01 |
SELECT * FROM TableA FULL OUTER JOIN TableB |
02 |
ON TableA. name = TableB. name |
The full outer join produces a and B's set. It is important to note, however, that for records that do not have a match, NULL is the value. |
|
1 |
SELECT * FROM TableA LEFT OUTER JOIN TableB ON TableA. name = TableB. name |
The left outer join produces a full set of table A, whereas a match in B table has a value, and no match is substituted with a null value. |
|
1 |
select * from tablea left outer join tableb on tablea. name = TableB. name where tableb.id is null |
Produces a collection that is available in table A and not in the B table. |
|
1 |
select * from tablea full outer join tableb on tablea. name = TableB. name where tablea.id is null or tableb.id is null |
produce datasets that do not appear in both A and B tables. |
|
It is also necessary to register that we also have a cross join of "cross-set", which is not represented by Wenshitu because it is a n*m combination of the data of table A and table B, that is, the Cartesian product. The expression is as follows:
This Cartesian product produces 4 x 4 = 16 records, which, in general, are seldom used in this syntax. But we have to be careful, if you do not use nested SELECT statements, the general system will produce a Cartesian product and then filter. This is very dangerous for performance, especially when the table is very large.
Various join joins for SQL