Der mehrteilige Bezeichner konnte nicht gebunden werden - Unterabfrage
Schema:
create table TableA (A1 int)
create table TableB (B1 int, B2 int)
create table TableC (C1 int)
Problematische Abfrage:
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
Das Erstellen dieses Schemas und Ausführen der Abfrage in SQLFiddle unter SQL Server 2008 führt zu folgenden Ergebnissen:
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
Die Verwendung von CROSS APPLY anstelle von INNER JOIN für die Unterabfrage behebt das Problem
Was ist das Problem?
Bearbeiten: Ich habe "TOP 1" hinzugefügt, das Teil der eigentlichen Abfrage war, und es ist ein relevanter Teil des Problems.
Edit2: Weitere Informationen zum Problem.