Can anyone help me with a complex sum, 3 table join mysql query?

Posted by Scarface on Stack Overflow See other posts from Stack Overflow or by Scarface
Published on 2010-03-31T04:30:28Z Indexed on 2010/03/31 4:33 UTC
Read the original article Hit count: 143

Filed under:

Hey guys I have a query and it works fine, but I want to add another table to the mix. The invite table I want to add has two fields: username and user_invite. Much like this site, I am using a point system to encourage diligent users. The current query which is displayed below adds the up votes and down votes based on the user in question: $creator. I want to count the number of entries for that same user from the invite table, and add 50 for each row it finds to the current output/sum of my query. Is this possible with one query, or do I need two?

"SELECT *, 
SUM(IF(points_id = \"1\", 1,0))-SUM(IF(points_id = \"2\", 1,0)) AS 'total'
FROM points LEFT JOIN post ON post.post_id=points.points_id WHERE post.creator='$creator'"

© Stack Overflow or respective owner

Related posts about mysql