我有两个这样的表:
Occupied Subject
+----------+-----------+ +----+---------+
| idClass | idSubject | | id | Name |
+----------+-----------+ +----+---------+
| 1 | 1 | | 1 | German |
| 1 | 2 | | 2 | English |
| 2 | 3 | | 3 | Math |
+----------+-----------+ +----+---------+
现在我想从一个特殊班级占用的所有科目中获取id和Name。我试过这个 SQL 语句:
SELECT S._id ,
S.Name
FROM Subject S
WHERE S._id = ( SELECT O.idSubject
FROM Occupied O
WHERE O.idClass = '1' -- '1' is variable and represents the special class
)
但我只从数据库中得到这个结果:
+----+---------+
| id | Name |
+----+---------+
| 2 | English |
+----+---------+
所以我输掉了德国队。我的错误在哪里?