33.3. Give Extra Join Information in Queries

Optimizers are not always able to draw conclusions that a human being can draw. The more information contained in the query, the better the chance that the optimizer will be able to find an improved execution plan. For example, to JOIN three tables together on a common column, you might write:

SELECT *
  FROM Table1, Table2, Table3
 WHERE Table2.common = Table3.common
   AND Table3.common = Table1.common;

Alternately, you might write:

SELECT *
  FROM Table1, Table2, Table3
 WHERE Table1.common = Table2.common
   AND Table1.common = Table3.common;

Some optimizers will JOIN pairs of tables based on the equi-JOIN conditions in the WHERE clause in the order in which they appear. Let us assume that Table1 is a very ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.