Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SQL Count group by records

Posted on 2014-08-24
5
Medium Priority
?
146 Views
Last Modified: 2014-08-29
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
0
Comment
Question by:J N
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40281970
Why attach an Excel spreadsheet instead of table dump?
0
 
LVL 6

Accepted Solution

by:
J N earned 0 total points
ID: 40281985
Hi,

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'

thanks
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40282099
For future reference, GROUP BY can work together with ORDER BY.
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40282295
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
0
 
LVL 6

Author Closing Comment

by:J N
ID: 40292145
i answered my own question with trail and error
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question