mike55 Posted October 15, 2004 Posted October 15, 2004 Hi all am attempting to do an inner select statement on a table, the table structure is as follows: StudentID, Course_Name, Year What i want to do is to count the no. of students on each course. The query must be setup in such a way that we get the course name from the table itself. SELECT Distinct(Course_Name), Count(StudentID) as Population FROM Details where (course_Name) = (Select Distinct(Course_Name) From Details) But this statement doesn't seem to work...any suggestions. Mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
*Experts* Nerseus Posted October 15, 2004 *Experts* Posted October 15, 2004 You need the "GROUP BY" clause of SQL: SELECT Course_Name, Count(StudentID) as Population FROM Details GROUP BY Course_Name The group by will give you a distinct list by its very nature. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.