Reputation: 73
If there are 3 tables and I wish to equi-join all of them.
Example Statement 1 : (Table_1 EQUIJOIN Table_2) EQUIJOIN Table_3
Example Statement 2 : (Table_2 EQUIJOIN Table_3) EQUIJOIN Table_1
When these statements are executed separately, are the outputs from both the statements same?
Upvotes: 0
Views: 189
Reputation: 781493
An Equi Join is just a particular case of INNER JOIN
where all the comparisons are equality. Since INNER JOIN
is associative and commutative, Equi Join must also be. See Does the join order matter in SQL? and Proof that Inner Join is Commutative.
Upvotes: 1
Reputation: 1270181
Yes. Equijoins are associative and commutative and all that. The ordering of the tables doesn't matter. The ordering of the conditions within each table doesn't.
You can sort of visualize this because an equi-join is a subset of the Cartesian product of all the tables. The joins are then filtering this down, and the order of the filters doesn't matter -- if a row is not in any of the filters, the ordering of the filters is irrelevant.
Upvotes: 1