Tips About Join

left and right join are outer join.
What happens after left joins? Example: [[183. Customers Who Never Order]]
1 | Create table If Not Exists Customers (id int, name varchar(255)) |
Without ON
In the left or right join, ON is necessary. However, in MySQL and join, ON is optional. In this case, using join without on will produce a cross join.
Condition in ON or WHERE
In the inner join, write conditions in on or where has no differences. However, if using a left join or right join, there is a difference. For example:
1 | SELECT * |
ON is a filter when producing the temp table, in the left join case it will return all left items and ignore the date condition in the above example. Different from ON, WHERE will execute after the temp table is produced. Thus it will delete all items that do not meet the conditions.