Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL COUNT Problem

Author  Topic 

layst
Starting Member

3 Posts

Posted - 2011-04-25 : 08:08:45
HELLO, I am having problems counting a particulat row from one table, while selecting multiple rows from two tables.
I have two tables, One called STUDENT and another called RESULTS.
I am trying to count the number of occurances a Student has an occurance of Assignment1Results.
Here is what i have so far that i cant seem to get working.


SELECT RESULTS.StudentID, STUDENT.StudentName, COUNT (RESULTS.StudentID)

FROM STUDENT, RESULTS


WHERE STUDENT.StudentID=RESULTS.StudentID AND REULTS.Assignment1Mark <> NULL



ORDER BY STUDENT.StudentName ASC;


The error i get is
You tried to execute a query that does not include the specified expression <name> as part of an aggregate function. (Error 3122)

I have got it to count the total number, but im trying to relate it to each individual occurance of the StudentID which connects the two tables.

Thanks in advance if you can help

By the way im using Access 2007

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-25 : 08:12:44
You just need to Group By
RESULTS.StudentID, STUDENT.StudentName

and see if that gives you your expected results.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

layst
Starting Member

3 Posts

Posted - 2011-04-25 : 08:17:57
quote:
Originally posted by jimf

You just need to Group By
RESULTS.StudentID, STUDENT.StudentName

and see if that gives you your expected results.

Jim

Everyday I learn something that somebody else already knew




Thanks, Worked perfectly.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-25 : 08:23:19
Your'e welcome. And welcome to SQL Team.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -