In SQL / MySQL, what is the difference between “ON” and “WHERE” in a join statement?

The ON clause defines the relationship between the tables.

The WHERE clause describes which rows you are interested in.

Many times you can swap them and still get the same result, however this is not always the case with a left outer join.

  • If the ON clause fails you still get a row with columns from the
    left table but with nulls in the columns from the right table.
  • If the WHERE clause fails you won’t get that row at all.

Leave a Comment