Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Count Distinct Schools for Student

Avatar of CuriousOne1
CuriousOne1Flag for Australia asked on
Microsoft AccessSQL
6 Comments1 Solution490 ViewsLast Modified:
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?
Avatar of Thomasian
ThomasianFlag of Philippines image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers