Jump to content

Recommended Posts

Hello,

 

I'm having problem and I really need your help

 

My Tabels:

 

Posts:                          Users:                        categories:

PostID                        UserId                        CatID

UserID                        Username                  CatName

 

 

I want to list Top poster in every category. Like:

 

cat1    user1    1000 posts

cat2      user2    900 posts

cat3      user1    1000 posts

 

so, I tried to do it  :D :

 

SELECT p.UserID, c.id, u.username, COUNT(PostID )
FROM Posts p
LEFT JOIN users u ON u.id = p.UserID 
LEFT JOIN categories c ON c.id = p.category
GROUP BY c.id, u.Username
ORDER BY COUNT(PostID ) DESC
LIMIT 27 

 

and the output:

 

UserID id username COUNT(PostID)

11886 45 user1               1299

11885 45 user2               756

11886 45 user1               751

11886 42 user1               491

 

 

as you can see there is 3 (cat id) repeated  :shrug:

 

please if anyone can help me, I will be grateful

Link to comment
https://forums.phpfreaks.com/topic/221259-problem-with-group-by/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.