我在一个数据库中有多个表;
UserAccount表; [UserAccount表] [1]
用户表 [用户表] [2]
EducationLevels表 EducationLevels table
请注意,Institution和EducationLevels表都有相同的名称。
我正在尝试使用;
查询数据库SELECT
Users.FirstName,
Users.LastName,
UserAccounts.OtherNames,
UserAccounts.Gender,
UserAccounts.DateOfBirth,
Institutions.Name as School,
EducationLevels.Name as Study
FROM
Users, UserAccounts,Institutions
WHERE
UserAccounts.HighestEducationLevelId = EducationLevels.Id
AND
UserAccounts.InstitutionId = Institutions.Id
AND
UserAccounts.UserId = Users.IdUserAccounts
AND
MobileNumber ='*****';
我收到错误:
Error Code: 1054. Unknown column 'EducationLevels.Name' in 'field
list'
答案 0 :(得分:0)
那是因为“FROM”子句没有表名。另外,在表名中添加别名,以便在查询中更容易使用它们。
SELECT
usr.FirstName,
usr.LastName,
accounts.OtherNames,
accounts.Gender,
accounts.DateOfBirth,
inst.Name as School,
eduLevel.Name as Study
FROM
Users usr, UserAccounts accounts, Institutions inst, EducationLevels eduLevel
....
答案 1 :(得分:0)
问题在于:
FROM Users, UserAccounts,Institutions
EducationLevels
表不存在
您忘记在FROM表名称列表中添加EducationLevels
,只有Users, UserAccounts,Institutions
。