Schema:
create table TableA (A1 int)
create table TableB (B1 int, B2 int)
create table TableC (C1 int)
Problematic query:
S
You cannot access an alias from a join inside of another joined subquery. You will need to use the following which joins the subquery on two columns/tables:
SELECT *
FROM TableA a
INNER JOIN TableB b
ON b.B1=a.A1
INNER JOIN
(
SELECT *
FROM TableC c
) d
ON d.C2=b.B2
AND d.C1 = b.B1
Or this can be written as:
SELECT *
FROM TableA a
INNER JOIN TableB b
ON b.B1=a.A1
INNER JOIN TableC c
ON c.C2=b.B2
AND c.C1 = b.B1