Advertisement

07.07.2008 at 06:49PM PDT, ID: 23545247
[x]
Attachment Details

Count Distinct Schools for Student

Asked by CuriousOne1 in Microsoft Access Database, SQL Query Syntax

Tags: MIcrosoft, access, 2003

How can I count the total number of distinct schools a student will be attending if they will attend multiple schools and do multiple courses throughout their education in one query?

Here is what I'm doing:

1st Query = [* CountStudentSchools_01]
----------------
SELECT StudentCourse.StdNo, StudentCourse.SchoolId
FROM StudentCourse
GROUP BY StudentCourse.StdNo, StudentCourse.SchoolId
ORDER BY StudentCourse.StdNo;


2nd Query
---------------
SELECT [* CountStudentSchools_01].StdNo, Count([* CountStudentSchools_01].SchoolId) AS CountOfSchoolId
FROM [* CountStudentSchools_01]
GROUP BY [* CountStudentSchools_01].StdNo
ORDER BY [* CountStudentSchools_01].StdNo;


The reason I didn't just do the count in the 1st Query as follows:
----------------
SELECT StudentCourse.StdNo, Count(StudentCourse.SchoolId) AS CountOfSchoolId
FROM StudentCourse
GROUP BY StudentCourse.StdNo
ORDER BY StudentCourse.StdNo;


...is because some students do several different courses at the same school, which means I get a duplicate count of some schools is this situation. The 2nd Query returns the correct count.

How can I do this is one query?
Start Free Trial
 
Keywords: Count Distinct Schools for Student
 
Loading Advertisement...
 
[+][-]07.07.2008 at 07:02PM PDT, ID: 21950198

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 07:13PM PDT, ID: 21950255

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 07:22PM PDT, ID: 21950290

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, SQL Query Syntax
Tags: MIcrosoft, access, 2003
Sign Up Now!
Solution Provided By: Thomasian
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.07.2008 at 07:27PM PDT, ID: 21950315

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 07:30PM PDT, ID: 21950330

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 07:35PM PDT, ID: 21950352

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628