我试图为我正在制作的游戏阶梯编写此声明。所有内部联接都有效,直到我将团队名称添加到等式中。
SELECT tblMatch.AttackingTeam,
tblMatch.DefendingTeam,
tblTeam.TeamName As AttackingTeamName,
tblTeam.TeamName As DefendingTeamName,
tblGameMaps.MapName AS MapName,
tblGameTypes.TypeShort AS TypeName,
tblStyles.StyleShort AS StyleName,
tblMatch.AttackingScore,
tblMatch.DefendingScore
FROM tblMatch
INNER JOIN tblGameMaps
ON tblGameMaps.MapID = tblMatch.MapID
INNER JOIN tblGameTypes
ON tblGameTypes.TypeID = tblMatch.TypeID
INNER JOIN tblStyles
ON tblStyles.StyleID = tblMatch.StyleID
INNER JOIN tblTeam A
ON A.TeamID = tblMatch.AttackingTeam
INNER JOIN tblTeam B
ON B.TeamID = tblMatch.DefendingTeam
WHERE LadderID=$ladderID AND (DefendingTeam=$teamID OR AttackingTeam=$teamID)
我得到的错误是
'字段列表'中的未知列'tblTeam.TeamName'
数据库确实有一个名为tblTeam的表,其中包含列tblTeamName。也许我只是看不到错误???
答案 0 :(得分:2)
您已将tblTeam
别名A
和B
,因此,不要使用tblTeam.TeamName
,而是使用A.TeamName
或B.TeamName
。要求。
答案 1 :(得分:0)
您在表tblTeamName
和tblTeam
中有SELECT
列TeamName
tblTeam.TeamName As AttackingTeamName,
tblTeam.TeamName As DefendingTeamName,
需要为同一列提供两次别名
答案 2 :(得分:0)
那么为什么要写行
tblTeam.TeamName As AttackingTeamName,
也许这就是问题(CTRL-F然后输入“tblTeam.TeamName As AttackingTeamName”)