User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Database Design section within the Web Development category of DaniWeb, a massive community of 426,850 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,100 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Database Design advertiser: Programming Forums

Query with Joins

Join Date: Sep 2005
Posts: 1
Reputation: ickchris is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ickchris ickchris is offline Offline
Newbie Poster

Query with Joins

  #1  
Sep 9th, 2005
I wish to extract a class list of students with assessment details on for a given term. The report must list all of the student names for the specified group, along with the assessment information for that term if it exists, otherwise the assessment part should be blank.

I am using the following query:

SELECT s.AdmissionNo, s.Surname, s.Forename, t.Progress, t.Effort, t.Behaviour, t.Classwork, t.Homework FROM Lessons l
INNER JOIN Students s ON l.AdmissionNo=s.AdmissionNo
LEFT OUTER JOIN Reports_Termly t ON t.LessonID=l.LessonID
WHERE l.GroupRef="mat/09/MS-M1" AND t.TermID="3"

The table definitions are as follows:

CREATE TABLE `students` (
`AdmissionNo` int(11) NOT NULL default '0',
`Surname` varchar(30) NOT NULL default '',
`Forename` varchar(30) NOT NULL default '',
PRIMARY KEY (`AdmissionNo`));

CREATE TABLE `lessons` (
`LessonID` int(10) unsigned NOT NULL auto_increment,
`GroupRef` varchar(20) NOT NULL default '',
`AdmissionNo` int(11) NOT NULL default '0',
PRIMARY KEY (`LessonID`));

CREATE TABLE `reports_termly` (
`LessonID` int(10) unsigned NOT NULL default '0',
`TermID` int(10) unsigned NOT NULL default '0',
`Progress` char(1) NOT NULL default '',
`Effort` tinyint(1) unsigned NOT NULL default '0',
`Behaviour` tinyint(1) unsigned NOT NULL default '0',
`Classwork` tinyint(1) unsigned NOT NULL default '0',
`Homework` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`LessonID`,`TermID`));

However, the query mentioned above does not return the students in the group that do not have any assessment details for this term (which I require it to do).

If anyone has any suggestions on how to do this, please let me know.

Thanks in advance

Chris
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 9:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC