Identyfikator wieloczęściowy nie mógł zostać powiązany - Podzapytanie
Schemat:
create table TableA (A1 int)
create table TableB (B1 int, B2 int)
create table TableC (C1 int)
Problematyczne zapytanie:
SELECT *
FROM TableA a
INNER JOIN TableB b ON b.B1=a.A1
INNER JOIN (SELECT TOP 1 *
FROM TableC c
WHERE c.C1=b.B1 ORDER BY c.C1) d ON d.C2=b.B2
INNER JOIN OtherTable ON OtherTable.Foo=d.C1
Budowanie tego schematu i uruchamianie zapytania w SQLFiddle w SQL Server 2008 powoduje:
The multi-part identifier "b.B1" could not be bound.: SELECT * FROM TableA a INNER JOIN TableB b ON b.B1=a.A1 INNER JOIN (SELECT TOP 1 * FROM TableC c WHERE c.C1=b.B1 ORDER BY c.C1) d ON d.C2=b.B2
Użycie CROSS APPLY zamiast INNER JOIN dla podzapytania rozwiązuje problem
Jaki jest problem?
Edytuj: Dodałem „TOP 1”, które było częścią prawdziwego zapytania i jest istotną częścią problemu.
Edit2: Dalsze informacje o problemie.