我有五個表:1.課程2.departmetns 3.students 4. enroll_courses 5.resultsMySQL查詢:如何寫內心的選擇加入查詢
Departments has id
Courses has id, department_id
Students has id,department_id
Enroll_courses has id, courses_id,students_id
Results has id, courses_id,students_id
我必須選擇courses.name這是在enroll_courses表,但不在結果表中。
我寫了查詢,我無法得到確切的答案。如果有人能幫我找到解決方案。
查詢:
SELECT courses.name
FROM courses
JOIN departments ON courses.department_id = departments.id
JOIN students ON departments.id = students.department_id
WHERE students.id = 9
AND courses.id IN (SELECT course_id FROM enroll_courses)
讓我們知道您的表格的設計,我們將能夠提供幫助。編輯原始問題,不要在評論中回覆。 –
您在這裏使用MySQL或MS SQL Server嗎?不要標記不涉及的產品。 – jarlh
您聲明您的課程表具有id,department_id,但是您引用了courses.name。更新所有領域,我們將有更多的機會。 –