我想弄清楚为什么这不起作用。我正在尝试选择每个成员的姓名以及每个成员注册的班级以及班级培训师姓名。
这就是我现在所拥有的:
SELECT
firstName, lastName, className, trainerName
FROM
member, _class, trainer, enrolment
WHERE
enrolment.memberID = member.memberID
AND enrolment.classID = _class.classID;
任何帮助或提示都会受到赞赏,因为我还在学习SQL。
额外信息:
enrolment
表包含列entrolmentID,memberID和classID trainer
表格包含列trainingID和trainerName member
表包含memberID,firstName,lastName,age,trainerID class
表包含classID,className,_day和trainerID 答案 0 :(得分:1)
JOIN
语句的有效语法是:
SELECT FIELD1
,...FIELDN
FROM TABLE1 T1
INNER JOIN TABLE2 T2 ON T1.FIELDX = T2.FIELDY
所以在你的情况下,使用:
SELECT firstName
,lastName
,className
,trainerName
FROM member
INNER JOIN enrolment ON enrolment.memberID = member.memberID
INNER JOIN _class ON enrolment.classID = _class.classID
INNER JOIN trainer ON trainer.trainerID = member.trainerID
答案 1 :(得分:0)
试试这个
SELECT firstname, lastname, classname, trainerName
FROM member
INNER JOIN enrollment
ON enrolment.memberID = member.memberID
INNER JOIN _class
ON enrollment.classID = class.classID
INNER JOIN trainer
ON trainer.trainerID = member.trainerID