Jump to content

A puzzle, help!


Yuki

Recommended Posts

Link to create and populate script: http://shahinrostami.com/webdevass2/draft.txt

 

Problem is this:

There are modules, there are tutors.

Tutors teach modules.

 

A module can be taught by more than one tutor, so there are three tables.

 

Tutor (tutorID and their info)

Module(moduleCode and its info)

Teaching(tutorID, moduleCode)  this is a composite key table

 

 

I have a combo box which I fill up with module names, I'm trying to get it to only list those that the tutor ISNT teaching.

 

 

It's not as simple as

 

SELECT module.module_Code, module.module_Name

FROM teaching

RIGHT JOIN module

USING (module_Code)

WHERE tutor_ID !=90000013

GROUP BY module.module_Code;

 

 

 

because of course another tutor may be teaching that module also, so the module is still accounted for. Also this only returns the modules that ARE being taught by someone. If the module currently has no tutors (null after right join) it doesn't include them!

 

help!

Link to comment
Share on other sites

That's not what I'm after

 

 

I need to return the list of modules the teacher does not teach.

 

 

Their are null values in the join, so I need a right join, there are also OTHER tutors with module codes in TEACHING

 

So if it finds

 

63PR2201  9000013

63PR2201  9000011

 

 

it'll != the 9000013 but include 9000011 in the results, see my problem?

 

 

 

 

 

I'm stuck

Link to comment
Share on other sites

$modulelist = 'SELECT module.module_Code \'module_Codes\', module.module_Name \'module_Name\''

        . ' FROM teaching'

        . ' RIGHT JOIN module'

        . ' USING (module_Code)'

       

        . ' WHERE tutor_ID is null or tutor_ID !=' . $tutor . ''

        . ' GROUP BY module.module_Code;';

 

 

 

Here's what I got so far.

 

 

This shows ALL modules that the TUTOR is not on AND the ones he is (because other tutors are on them)

 

 

Someone must have a big brain hooked up to other brains!

 

Link to comment
Share on other sites

Brilliant, thank you Barand, second time you've helped me out, problem solved!

 

SELECT m.module_Code, m.module_Name

FROM module m

LEFT JOIN teaching t ON m.module_Code = t.module_Code AND t.tutor_ID= 90000001

WHERE t.tutor_ID IS NULL;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.