dbTalk Databases Forums  

query help

comp.database.ms-sqlserver comp.database.ms-sqlserver


Discuss query help in the comp.database.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Patrick
 
Posts: n/a

Default 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



Reply With Quote
  #2  
Old   
scott.x.lu (Offline)
Junior Member
 
Posts: 5
Join Date: Jun 2006

Default 07-05-2006 , 02:40 AM






(COURSE.Course_Name = 'Databases') or (Course.Course_Name = 'Networking)

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.