Skip to content
Advertisement

How to retrieve count of records in SELECT statement

I am trying to retrieve the right count of records to mitigate an issue I am having. The below query returns 327 records from my database:

Where I run into trouble is trying to reconcile that with the below query. One is for showing just a count of all the particular students the other is showing pertinent information for a set of students as needed but the total needs to be the same and it is not. The below query return 333 students – the reason is because the school the student goes to is in two separate counties and it counts that student twice. I can’t figure out how to fix this.

Advertisement

Answer

If you just want the count, then perhaps count(distinct) will solve the problem:

I don’t see what at.someid refers to, so perhaps:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement