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?
Asked
Active
Viewed 163 times
0

Abhishek Agarwal
- 63
- 1
- 4
-
1What do you mean by equijoin? Some people consider only inner joins, others consider any join so long as it only uses equality checks. The answer depends on which meaning you use. – May 07 '17 at 16:40
2 Answers
1
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.

Gordon Linoff
- 1,242,037
- 58
- 646
- 786
1
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.