There are a few discussions on StackOverflow of commutativity of joins, such as 1, 2, 3, and 4. It gets pretty complicated, and I don't think any of them answers my question here.
I've often noticed that when I put the SQL for a query into Access, Access messes with the order of my joins, and even changes LEFT
joins to RIGHT
ones. I generally write my outer joins as LEFT
s, laying out the sequence of joined tables logically, so I don't like it when Access messes that up. But now I've noticed a difference in how a query is represented in Design View, and I want to know if the difference is significant.
Here are three queries:
Query1
SELECT Table1.ID_Table1
FROM Table2 RIGHT JOIN (Table1 LEFT JOIN Table12
ON Table1.ID_Table1 = Table12.ID_Table1) ON Table2.ID_Table2 = Table12.ID_Table2;
Query2
SELECT Table1.ID_Table1
FROM Table1 LEFT JOIN (Table2 RIGHT JOIN Table12
ON Table2.ID_Table2 = Table12.ID_Table2) ON Table1.ID_Table1 = Table12.ID_Table1;
Query3
SELECT Table1.ID_Table1
FROM Table1 LEFT JOIN (Table12 LEFT JOIN Table2
ON Table12.ID_Table2 = Table2.ID_Table2) ON Table1.ID_Table1 = Table12.ID_Table1;
I prefer Query3 because it has the logical order I mentioned.
When I entered these queries as SQL, Access changed the code of Query2 to be the same as Query1, and it did not modify the code of Query1 or Query3. When the three queries are run (with very simple data, so not conclusive), they all produce the same result. In Design View, Query1 and Query2 look identical, which is good since Access converted Query2 into Query1. Query3 looks almost the same, except that the relationship between Table2 and Table12, which is represented in the view of Query1 and Query2 is not represented in the view of Query3.
So my question is, is Query3 equivalent to Query1 and Query2, so that it's safe to ignore the loss of the representation of the table relationships in Design View, or is there an operational difference in the queries? If there is a difference, is there a guiding principle for ordering of joins?