Joins
Joins are often one of the hardest topics for MySQL newcomers to grasp. The entire concept pivots on the understanding of mathematical sets, unions, intersections, and their resulting Venn diagrams. Another way of looking at joins is to use tabular information. For an example of this, see: http://en.wikipedia.org/wiki/Sql_join.
In the preceding Venn diagram, the left circle may be seen to represent one set and the right circle another. The overlapping area is called the intersection of the two sets. The set of elements that encompasses the contents of both circles is called a union, but should not be confused with the MySQL keyword UNION
. With that information in mind, we can then see how MySQL allows us to access different parts of the Venn diagram through joins.
LEFT and RIGHT joins
In MySQL, each set is represented by a table. The first table referenced in the query is the set on the left. The second is represented by the circle on the right. For MySQL to know which is the primary...