Jump to content

Recommended Posts

Hey guys, here is what I'm trying to do:

 

I have a table width user data.

 

I have a table width posts from users.

 

I have a table with people's votes of the posts.

 

Can I get the number of people who voted for a post made by a particular user?

 

I could fetch all posts made by a certain user, but who do I "scan" for all votes using this array?

 

thanks!

Hi

 

Something like the following would get you a count of all the votes for each post by each user:-

 

SELECT a.users_id, a.UserName, b.PostTitle, COUNT(c.Vote)
FROM users a
INNER JOIN posts b ON a.users_id = b.users_id
INNER JOIN votes c ON b.post_id = c.post_id
GROUP BY a.users_id, a.UserName, b.PostTitle

 

However not sure whether this is what you want, or whether you only care about one users posts.

 

All the best

 

Keith

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.