0

I have the following query:

SELECT a.feeder_id, b.feeder_pr FROM authors_article_feeders a LEFT JOIN feeders b ON b.id = a.feeder_id WHERE website_id =1 LIMIT 0 , 30 

which results in:

feeder_id feeder_pr 18 2 18 2 18 2 18 2 32 6 

What I need is to modify the above query so that it will manipulate this data so that the result would end up with a count of each feeder_pr, so in this case the result would be:

feeder_pr count 2 4 6 1 

Any assistance is appreciated. If you have time please describe your solution so that I can learn from it while I'm at it.

Everything I've tried has ended in inaccurate results, usually with just one row instead of the expected 2.

1
  • 1
    What you need is select b.feeder_pr,count(b.feeder_pr) group by b.feeder_pr with your existing joins, you may not by giving the group by thats why you end up with one row Commented Mar 14, 2012 at 3:48

2 Answers 2

4

You just need to add a GROUP BY And, you would not even need the joins

SELECT b.feeder_pr, COUNT(b.feeder_pr) FROM feeders b GROUP BY b.feeder_pr 
Sign up to request clarification or add additional context in comments.

4 Comments

No problem, please don't forget that appreciation is best shown with a checkmark :)
:) I plan to in 4 minutes when it will let me ;)
Oh haha, I didnt realize there was a time limit on that. Thanks!
Yea, I'm not sure what it is, maybe 10-15 minutes or so after the initial question is asked.
0
SELECT b.feeder_pr, count(a.feeder_id) as count FROM authors_article_feeders a LEFT JOIN feeders b ON b.id = a.feeder_id WHERE website_id =1 GROUP BY 1 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.