I recently wrote a post about inner and outer joins, and a couple of people
asked what the difference is between USING
and
ON
.
In a nutshell, you use ON
for most things, but
USING
is a handy shorthand for the situation where
the column names are the same.
Consider this example dataset:
mysql> select * from pets; +---------+---------+--------+-----------+ | pets_id | animal | name | owners_id | +---------+---------+--------+-----------+ | 1 | fox | Rusty | 2 | | 2 | cat | Fluffy | 2 | | 3 | cat | Smudge | 3 | | 4 | cat | Toffee | 3 | | 5 | dog | Pig | 3 | | 6 | hamster | Henry | 1 | | 7 | dog | Honey | 1 | …[Read more]