query help -
01-19-2005
, 09:14 PM
For part of a school project, I have to write a query to answer:
Which students are enrolled in both Databases and Networking? (Hint: Use the
SECTION_ID for each class so you can determine the answer from the
IS_REGISTERED table by itself.)
Here are the tables:
* is PK, ** is FK
Student (Student_ID*, Student_Name)
Course (Course_ID*, Course_name)
Section (Section_ID**, Course_ID**)
Is_Registered (Student_ID**, Section_ID**)
Here is as close as I get. I can get a correct answer (Student_name is
taking Course_name) when using only one argument in the where clause, but
when I use 2 arguments (ie, where this=whatever AND that=something else) I
should still get one row, but I get zero. My data is verified and
reverified. My query is wrong, I think. I would like to have a
recommendation for a book on how to write a query with 3 or 4 joins, too.
TIA! here's my attempt:
SELECT STUDENT.Student_Name, COURSE.Course_Name
FROM COURSE INNER JOIN
SECTION ON COURSE.Course_ID = SECTION.Course_ID INNER JOIN
IS_REGISTERED ON [SECTION].Section_ID = IS_REGISTERED.Section_ID INNER
JOIN
STUDENT ON IS_REGISTERED.Student_ID = STUDENT.Student_ID
WHERE
(COURSE.Course_Name = 'Databases') and (Course.Course_Name = 'Networking)
psully at eatel dot net |