SELECT CoachFirst AS 'First Name', CoachLast AS 'Last Name', CoachCity AS 'City', TeamName AS 'Team'
FROM tblCoaches A,
tblTeams B
WHERE A.CoachID = B.TeamCoach
AND CoachCity = 'Bowmanville' AND 'Whitby';
每次执行代码时,我都会收到错误
我想你打算IN
:
SELECT c.CoachFirst AS FirstName, c.CoachLast AS LastName, c.CoachCity AS City,
t.TeamName AS Team
FROM tblCoaches c JOIN
tblTeams t
ON c.CoachID = t.TeamCoach
WHERE t.CoachCity IN ('Bowmanville', 'Whitby');
请注意我所做的其他更改:
- 使用正确、明确、标准
JOIN
语法。切勿在FROM
子句中使用逗号。 - 使用有意义的表别名,而不是任意的。
- 限定所有列引用,以便了解它们的来源。
- 不要对列别名使用单引号。 实际上,只需使用不需要转义字符的别名即可。