<<< Previous question <<< Question ID#0722.md >>> Next question >>>
Considering the table structure below what MySQL query will load a result set containing all students names enrolled in the programming classes ?
--students table:
| studentid | name |
--------------------
| 1 | Mike |
| 2 | John |
| 3 | Jeff |
| 4 | Anne |
--classes table:
| classid | classname
-------------------------
| 1 | Math
| 2 | Programming
| 3 | Biology
classes_to_students table:
| studentid | classid
-------------------------
| 1 | 1
| 2 | 2
| 3 | 2
| 4 | 3
- A)
SELECT s.name FROM students as s
WHERE s.studentid IN (
SELECT studentid
FROM classes_to_students as cs
INNER JOIN classes as c ON cs.classid = c.classid
WHERE c.classname = 'Programming'
);
- B)
SELECT s.name FROM students as s
INNER JOIN classes_to_students as cs ON s.studentid = cs.studentid
INNER JOIN classes as c ON c.classid = cs.classid
WHERE c.classname='Programming';
- C)
SELECT s.name FROM students as s
INNER JOIN classes as c ON s.studentid = c.classid
INNER JOIN classes_to_students as cs ON s.studentid = cs.studentid
WHERE c.classname = 'Programming';
- D)
-- none
Answer
Answer: A, B