BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Where am I wrong in this 3-table left join query?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Wei
Guest





PostPosted: Sat Aug 28, 2004 12:44 pm    Post subject: Where am I wrong in this 3-table left join query? Reply with quote




I have tables student_course, completion, withdrawal.
The schema are similar: studentid string, courseid string
With completion containing all the completed courses, withdrawal containing all the withdrawed students. And student_course containing all current active student-course combination and completions and withdrawals.

Now I want to find out a student's current active courses, which is basically student_couser MINUS completion MINUS withdrawal.
My query is as follows:

select a.*
from std_course a left join completion b on (a.learnerid = b.learnerid and a.COURSECODE=b.COURSECODE) left join withdrawal c on (a.learnerid= c.learnerid and a.LEARNERID=c.COURSECODE)
where b.COURSECODE is null and c.COURSECODE is null;

Now this query only returns student_course MINUS completion. The withdrawal records are still there. How should I correct this query?
Back to top
Wayne Niddery [TeamB]
Guest





PostPosted: Sat Aug 28, 2004 3:25 pm    Post subject: Re: Where am I wrong in this 3-table left join query? Reply with quote



Wei wrote:
Quote:
I have tables student_course, completion, withdrawal.

Please do not cross-post or multi-post.
See the newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html

I replied to this in .database.desktop.

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"The purpose of morality is to teach you, not to suffer and die, but to
enjoy yourself and live." - Ayn Rand



Back to top
corey lawson
Guest





PostPosted: Tue Oct 19, 2004 7:01 am    Post subject: Re: Where am I wrong in this 3-table left join query? Reply with quote



Wei wrote:

Quote:
I have tables student_course, completion, withdrawal.
The schema are similar: studentid string, courseid string
With completion containing all the completed courses, withdrawal containing all the withdrawed students. And student_course containing all current active student-course combination and completions and withdrawals.

Now I want to find out a student's current active courses, which is basically student_couser MINUS completion MINUS withdrawal.
My query is as follows:

select a.*
from std_course a left join completion b on (a.learnerid = b.learnerid and a.COURSECODE=b.COURSECODE) left join withdrawal c on (a.learnerid= c.learnerid and a.LEARNERID=c.COURSECODE)
where b.COURSECODE is null and c.COURSECODE is null;

Now this query only returns student_course MINUS completion. The withdrawal records are still there. How should I correct this query?

Combine the two tables, Completion and Withdrawl, perhaps named
StudentCourseHistory. Indicate with two flags whether a given course has
been completed or withdrawn from from in this table. Then, selecting
active courses is simply selecting the records for a student that don't
have either of these two flags set.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.