-1

I have 2 tables A and B and there is a left outer join between them.

A LEFT OUTER JOIN B ON A.ID = B.CODE

Will swapping the left and right operands of = in the ON condition ...

A LEFT OUTER JOIN B ON B.CODE = A.ID

... change anything performance wise or return different set of rows?

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
fledgling
  • 991
  • 4
  • 25
  • 48
  • 1
    This is the right duplicate; http://stackoverflow.com/questions/785583/does-the-order-of-tables-referenced-in-the-on-clause-of-the-join-matter – Tim Schmelter Sep 22 '15 at 15:37
  • 1
    Probably this is indeed a duplicate, but not of the question designated. That one is about the order of the *tables* in a join. This one is about swapping the left and right operands of `=` in a join predicate. Of course, exchanging the left and right operands of `=` makes no difference, neither in a join predicate nor elsewhere. – John Bollinger Sep 22 '15 at 15:37
  • This question is slightly different than the linked duplicate. The duplicate linked relates to JOIN order, not ON order. – Greg Viers Sep 22 '15 at 15:38
  • @JohnBollinger: no, the question is an exact duplicate. But the accepted answer is only answering it at the end: _"As for the order in the comparison, it doesn't matter in any RDBMS, AFAIK."_ – Tim Schmelter Sep 22 '15 at 15:45
  • All the optimization the query optimizer does and you think the order of the = can make a difference. A = B versus B = A is the same evaluation. – paparazzo Sep 22 '15 at 15:57

1 Answers1

0

Will reversing the ON condition return a different set of rows? No.

Will reversing the ON condition change performance? It shouldn't, but it might. Any difference in performance would be negligible.

Greg Viers
  • 3,473
  • 3
  • 18
  • 36