45
45
**Different kinds of SQL JOINs**
47
Here are the types of JOIN you can use, and the differences between them. Click for detailed syntax and examples:
49
* JOIN: Return rows when there is at least one match in both tables
50
* LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table
51
* RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
52
* CROSS JOIN: Return rows when there is a match in one of the tables
56
Implicit cartesian products of the form ``SELECT * FROM t1, t2`` without a
57
``WHERE`` or ``ON`` condition will error. If such behaviour is intended
58
please use ``SELECT * FROM t1 CROSS JOIN t2``.
62
how joins are executed. i.e. nested loop join.
47
Here are the types of JOIN you can use, and the differences between them:
49
**JOIN:** Return rows when there is at least one match in both tables
51
**LEFT JOIN:** Return all rows from the left table, even if there are no matches in the right table
53
**RIGHT JOIN:** Return all rows from the right table, even if there are no matches in the left table
55
**CROSS JOIN:** Return rows when there is a match in one of the tables
58
*Note:** Implicit cartesian products of the form ``SELECT * FROM t1, t2`` without a ``WHERE`` or ``ON`` condition will error. If such behavior is intended please use ``SELECT * FROM t1 CROSS JOIN t2``.
61
**How joins are executed**:
63
In its simplest form, a nested loop join works like this: It compares each row from one table (which can be considered the outer table) to each row from the other table (which can be considered the inner table), looking for rows that satisfy the join predicate. ('Inner table' and 'outer table' simply correlate to the inputs of the join, while 'inner join' and 'outer join' refer to the logical operations.)
65
The total number of rows compared is proportional to the size of the outer table multiplied by the size of the inner table. To minimize the cost of the operation, reduce or minimize the number of inner rows that we must compared to each outer row.
72
* Cross apply and outer apply
73
* Left semi-join and left anti-semi-join