henricar Posted April 6, 2011 Share Posted April 6, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/232877-not-to-sure-how-to-go-about-doing-this-query/ Share on other sites More sharing options...
Maq Posted April 6, 2011 Share Posted April 6, 2011 Moving to SQL section. Quote Link to comment https://forums.phpfreaks.com/topic/232877-not-to-sure-how-to-go-about-doing-this-query/#findComment-1197751 Share on other sites More sharing options...
kickstart Posted April 6, 2011 Share Posted April 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232877-not-to-sure-how-to-go-about-doing-this-query/#findComment-1197760 Share on other sites More sharing options...
henricar Posted April 8, 2011 Author Share Posted April 8, 2011 hey thanks for the reply! sorry I took a while to answers but I've been studying for finals and I'm in over my head but what exactly do the a b c and do here? Quote Link to comment https://forums.phpfreaks.com/topic/232877-not-to-sure-how-to-go-about-doing-this-query/#findComment-1198878 Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2011 Share Posted April 8, 2011 They're aliases for the table names. users a, posts b, votes c . . . Quote Link to comment https://forums.phpfreaks.com/topic/232877-not-to-sure-how-to-go-about-doing-this-query/#findComment-1198882 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.