STUDENT
StudentID | StudentName
1 | 'John'
2 | 'Mary'
3 | 'Steven'
REGISTRATION
StudentID | ClassNum
1 | 1000
1 | 1001
2 | 1000
3 | 2000
4 | 1000
I would like to only display studentID's that have ClassNum 1000 AND ClassNum 1001. They must have both to be printed out to show up. When I try to look up AND with WHERE statements, they usually have them asking two different columns.
When I try to look up AND with WHERE statements, they typically have them asking two different columns. I think this is because it is looking for a Student that has both at the same time, ClassNum 1000 AND ClassNum 1001, which isn't possible with this dataset. I want John to be the only one that shows up.
Ideal Result
1 | 1000
1 | 1001
Only display the student that has both class 1000 and 1001.
However, if SQL can do the following, that would be even better
1 | 1000 & 1001
That would be ideal, but I don't think that is possible. For now, only print a Student that has both
STUDENT(__StudentID, StudentName)
REGISTRATION(__StudentID, __ClassNum)
My code:
SELECT s.StudentName, r.ClassNum FROM STUDENT s
INNER JOIN REGISTRATION r ON r.StudentID = s.StudentID
WHERE ClassNum = '1000' AND ClassNum = '1001';
Nothing
Also played around with
SELECT s.StudentName, r.ClassNum FROM STUDENT s
INNER JOIN REGISTRATION r ON r.StudentID = s.StudentID
WHERE ClassNum IN ('1000', '1001');
It gives me all the students with any of them, but I want one that has both.