SQL Count group by records


i am trying to create an sql statement to count particular group by rows

i am currently using the folloing sql statement

SELECT COUNT(*) AS count FROM photos WHERE status='active' GROUP BY photographer

which im tying to get yield 3 however it returns 797

what am i missing

J NUnicorn wranglerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Why attach an Excel spreadsheet instead of table dump?
J NUnicorn wranglerAuthor Commented:

Im not sure i thought it was an easy option

however i seem to arrived at the results i was looking for

SELECT COUNT(DISTINCT photographer) AS count FROM photos WHERE status='active'


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
For future reference, GROUP BY can work together with ORDER BY.
it was a good lesson

If you are trying to count the photographers by rummaging through the photos, then you need DISTINCT

What you had with the first query is the number of photos WHERE status='active'

Not absolutely sure what Ray was alluding to, but to get a count per photographer would require a group by

SELECT photographer, COUNT(*) AS cnt FROM photos WHERE status='active' GROUP BY photographer
J NUnicorn wranglerAuthor Commented:
i answered my own question with trail and error
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.