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
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
Why attach an Excel spreadsheet instead of table dump?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
i answered my own question with trail and error