I have "enrollment" table with the following structure:
CREATE TABLE enrollment (
enrollmentID bigint(20) NOT NULL auto_increment,
coursename varchar(200) NOT NULL default '',
studentID int(4) NOT NULL default '0',
semestername varchar(100) NOT NULL default '',
PRIMARY KEY (enrollmentID)
)
This table is populated with coursenames that students have enrolled in a particular semester.
Given a semestername and coursename, my Select query is trying to retrieve all the coursenames and count of the number of students enrolled in each of the courses for the given semester (except for the given course).
SELECT a.coursename, COUNT( * ) AS count
FROM enrollment AS a, enrollment AS b
WHERE b.coursename = "CSC001 - abcdef"
AND b.semestername = "Fall 2005"
AND a.coursename != "CSC001 - abcdef"
AND a.studentID = b.studentID
ORDER BY count
GROUP BY a.coursename
LIMIT 10;
Basically I'm trying to get the courses that should not be scheduled at the same time as that of the given course.
The query is retrieving the correct courses that I need, but the count returned is incorrect.
Any help is appreciated.
Thanks,
Sunder.