Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,583 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,928 people online right now. Registration is fast and FREE... Join Now!




Basic question, but stuck

 
Reply to this topicStart new topic

Basic question, but stuck

skin__
6 Oct, 2008 - 12:01 AM
Post #1

New D.I.C Head
*

Joined: 20 May, 2008
Posts: 37

Hey guys, I have a query that looks like this:
SELECT title, name FROM lecturers
WHERE staff_no IN
(SELECT staff_no FROM units
WHERE unit_code IN
(SELECT unit_code FROM exams
WHERE stu_no IN
(SELECT stu_no FROM students
WHERE degree = 'M402')));

I need to change it so that it only displays the title/name of the lecturers who teach units with more than three students doing the degree 'M402'.

I'm sure it's really simple, but it has been a long day.

Thanks!
User is offlineProfile CardPM
+Quote Post

pemcconnell
RE: Basic Question, But Stuck
6 Oct, 2008 - 02:54 AM
Post #2

D.I.C Regular
Group Icon

Joined: 5 Aug, 2008
Posts: 396



Thanked: 37 times
Dream Kudos: 75
My Contributions
Didn't get time to review this but it should work:

CODE

SELECT a.title, a.name FROM lecturers a INNER JOIN units b ON a.staff_no = b.staff_no INNER JOIN exams c ON b.unit_code = c.unit_code INNER JOIN students d ON c.stu_no = d.stu_no WHERE d.degree = 'M402'


Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

Hary
RE: Basic Question, But Stuck
6 Oct, 2008 - 04:52 AM
Post #3

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 205



Thanked: 15 times
My Contributions
You're missing the requirement of at least 3 students, for which you need a GROUP BY, with a COUNT. Try it with that before we do your homework wink2.gif
User is offlineProfile CardPM
+Quote Post

skin__
RE: Basic Question, But Stuck
6 Oct, 2008 - 08:07 PM
Post #4

New D.I.C Head
*

Joined: 20 May, 2008
Posts: 37

Do you mean like this:

CODE
SELECT a.title, a.name FROM lecturers a
INNER JOIN units b ON a.staff_no = b.staff_no
INNER JOIN exams c ON b.unit_code = c.unit_code
INNER JOIN students d ON c.stu_no = d.stu_no
WHERE d.degree = 'M402'
GROUP BY title
HAVING COUNT(*) >=3;


Because the output dosn't look right? It always has one result (the same one) no matter how low I take the number 3.

I guess I should post another problem I'm having since it's a similar problem. For each room I'm meant to show all the students who have at least 4 classes in that room. My query looks like:

CODE
SELECT r.room_no, s.name FROM student s , room r
WHERE stu_no IN
(SELECT stu_no FROM student)
HAVING COUNT(*) >=4;


But I don't think it's right. HELP!

This post has been edited by skin__: 6 Oct, 2008 - 10:34 PM
User is offlineProfile CardPM
+Quote Post

Trogdor
RE: Basic Question, But Stuck
7 Oct, 2008 - 08:00 AM
Post #5

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 523



Thanked: 3 times
Dream Kudos: 125
My Contributions
SELECT a.title, a.name FROM lecturers a
INNER JOIN units b ON a.staff_no = b.staff_no
INNER JOIN exams c ON b.unit_code = c.unit_code
INNER JOIN students d ON c.stu_no = d.stu_no
WHERE d.degree = 'M402'
GROUP BY title
HAVING COUNT(d.stu_no) >=3;
or something like that?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:42AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month