I have three versions of the same select query (SQL Fiddle here):
CREATE TABLE MainTable(ID INT)
CREATE TABLE SubTable(ID INT, Type CHAR(2))
CREATE TABLE SubTableType(Type CHAR(2))
INSERT MainTable VALUES (1), (2)
INSERT SubTable VALUES (1, 'AB'), (2, 'AB'), (3, 'CD')
INSERT SubTableType VALUES ('AB')
SELECT *
FROM MainTable P
JOIN SubTable L
ON P.ID = L.ID
JOIN SubTableType LT
ON L.Type = LT.Type
SELECT *
FROM MainTable P
JOIN SubTable L
JOIN SubTableType LT
ON L.Type = LT.Type
ON P.ID = L.ID
SELECT *
FROM MainTable P
JOIN SubTable L
JOIN SubTableType LT
ON P.ID = L.ID
ON L.Type = LT.Type
The first two select statements work and produce the same result. The third reports the error,
The multi-part identifier "P.ID" could not be bound.
This question appears to claim that the first two queries are semantically equivalent, though they may perform differently. My question is rather about the syntax. I've always written joins according to the first pattern, and I didn't even realize that the second pattern was permissible. Clearly it is, but then why isn't the third pattern also acceptable? The main documentation doesn't seem to touch on this, so I'm trying to find documentation that spells out what is and isn't permissible.