Skip to content
Advertisement

Condition within JOIN or WHERE

Is there any difference (performance, best-practice, etc…) between putting a condition in the JOIN clause vs. the WHERE clause?

For example…

Which do you prefer (and perhaps why)?

Advertisement

Answer

The relational algebra allows interchangeability of the predicates in the WHERE clause and the INNER JOIN, so even INNER JOIN queries with WHERE clauses can have the predicates rearrranged by the optimizer so that they may already be excluded during the JOIN process.

I recommend you write the queries in the most readable way possible.

Sometimes this includes making the INNER JOIN relatively “incomplete” and putting some of the criteria in the WHERE simply to make the lists of filtering criteria more easily maintainable.

For example, instead of:

Write:

But it depends, of course.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement