我正在练习ORACLE SQL。
目前我有3张桌子。
Student values = "student_id ,name"
Subjects values = "subject_id, name"
Scores values = "score, student_id, subject_id"
我正在尝试从数据库中检索以下信息。
学生姓名,科目的名称和ID,最后是具有student_id“ 34560”的分数。
SELECT scores.score,
scores.subject_id,
student.name,
subject.subject_id,
subject.name
FROM scores
INNER JOIN students
ON scores.student_id = '34560'
INNER JOIN subject
ON /* and here's where i'm lost*/
有没有一种方法可以将查询的第一部分全部合并在一起,即我将Student_id =“ 34560”的学生列表称为学生列表,然后查询该列表以查看其是否与subject_id匹配?
答案 0 :(得分:2)
使用in
运算符获取学生ID列表
SELECT sc.score, sc.subject_id,
st.name, sb.subject_id, sb.name
FROM scores sc
INNER JOIN students st
ON sc.student_id = st.student_id
INNER JOIN subject sb
ON sc.subject_id=sb.subject_id
where sc.student_id in ('34560','add_anotherstudentid','add_anotherstudentid') //you can add multiple student id