Link to home
Start Free TrialLog in
Avatar of J N
J N

asked on

SQL Count group by records

Hi

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

thanks
photos.xls
Avatar of Gary
Gary
Flag of Ireland image

Why attach an Excel spreadsheet instead of table dump?
ASKER CERTIFIED SOLUTION
Avatar of J N
J N

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of J N
J N

ASKER

i answered my own question with trail and error