Jump to content

Query to display fields that meet a criteria


jd307

Recommended Posts

The subject isn't very descriptive of the issue that I am having to over come.  Basically, the problem is part of the timetabling system that I am building.  The criteria states I must write a query in SQL (this is for an MS Access 2003 database, so not exactly MySQL) that can list available and suitable tutors.  Basically, the idea is that if a tutor is unavailable for a session they are going to teach (i.e they have called in sick), the coordinator must find another tutor.  As it is a music school, the tutor must be able to play the instrument for the class, but must not be teaching another lesson.

 

Here is what I have so far:

SELECT     RTRIM(tutor.firstName)+' '+RTRIM(tutor.lastName) AS Tutor_Name, tutor_skill.level, startTime
FROM       tutor, tutor_skill, instrument_type, tutor_availability, tutor_session, session
WHERE     tutor.tutorID = tutor_skill.tutorID
AND          tutor_skill.instrumentTypeID = instrument_type.instrumentTypeID
AND          instrumentType = "guitar"
AND          tutor.tutorID = tutor_availability.tutorID
AND          termID = 11
AND          tutor.tutorID = tutor_session.tutorID
AND          tutor_session.sessionID = session.sessionID
AND          startTime<>#15:0:0#

 

This works perfectly for what I want.  It displays the tutor name, their skill level (in the stated instrument, guitar in this case) and start times of their sessions.  From this statement it shows ALL tutors who are available during the term (term 11), and who can play the guitar.  As the session is at 3pm, it removes all tutors who have lessons at 3pm (as per the last line).

 

The problem is, John Smith has lessons at 9am, 12pm and 3pm.  This query removes the record for John Smith at 3pm but still shows him in the list (with the times of 9am and 12pm.  What I want to do is say "IF tutor has a session at #15:0:0# then do not display him at all"  instead of "show all occurances of this tutor, except for the time stated", which is what it is doing. 

 

Any ideas how this can be achieved, purely in SQL.

 

Thanks.

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.