Jump to content

Return results based on values of another record in same table

Recommended Posts


I have a query that goes like this 


SELECT s.studentid, firstname,lastname,dp,startyear,sum(credits)

FROM students s, results r, courses c

WHERE s.studentid=r.studentid 

AND r.courseid=c.courseid

GROUP BY s.studentid 

HAVING (dp, startyear) = (SELECT dp, startyear FROM students WHERE studentid=18);

I need to filter it so that it only returns those that have credits less than student 18. I am stuck now as to how to do that.  Any ideas?

Also this one above misses out one record as they have no credits. How could I get it still to display the name etc but the sum to read as 0? 

Thanks in advance



Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...