Jump to content

not to sure how to go about doing this query...


henricar

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.