Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

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*
Posted

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

"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

Join the conversation

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

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