SQL 使用多个表别名

SQL aliasing with multiple tables

我正在寻找 select 我的报告、播放器和夹具 table 中的所有字段,其中报告 table 中的 FixtureID 与 @FixtureID 匹配(select 从组合框编辑)。但是,我无法让别名正常工作 - 我尝试以与 Report 和 Fixture 相同的方式为 Player table 添加别名,但这也会引发错误。

               SELECT 
                    r.*,
                    Player.*,
                    f.*,
                    isNull(Player.PlayerFirstName + ' ' + Player.PlayerLastName, ' ') AS 'PlayerName' 
                FROM 
                    Report AS r, Fixture AS f
                INNER JOIN Player ON Player.PlayerID = r.PlayerID
                INNER JOIN f ON f.FixtureID = r.FixtureID
                WHERE
                    r.FixtureID = @FixtureID
                ORDER BY 
                    ReportDate

错误状态:"The multi-part identifier "r.PlayerID“无法绑定”。

如有任何建议,我们将不胜感激。

试试这个...

SELECT r.*
    ,Player.*
    ,f.*
    ,isNull(Player.PlayerFirstName + ' ' + Player.PlayerLastName, ' ') AS 'PlayerName'
FROM Report AS r
INNER JOIN Player ON Player.PlayerID = r.PlayerID
INNER JOIN Fixture AS f ON f.FixtureID = r.FixtureID
WHERE r.FixtureID = @FixtureID
ORDER BY ReportDate