Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7963129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:32:28+00:00 2026-06-04T05:32:28+00:00

I have been fiddling with creating my own message board, and though it is

  • 0

I have been fiddling with creating my own message board, and though it is working fine I wanted to add post voting to it (diagram at the end of the post).

I pulled the data I wanted from my two tables msgboard_user and msgboard_post like this:

SELECT p.post_id, p.user_id, u.username, get_time_diff(p.date) as date, p.ip, p.text, p.parent_post_id, p.approved AS posts
FROM msgboard_post p, msgboard_user u
WHERE p.user_id = u.user_id
AND p.approved = "yes"
ORDER BY p.date DESC
-- code for limit...

So now I need to be working with a third table, msgboard_vote. Every vote gets one row in the table and I would like to have one column in my result that sums the votes for that post. The vote (vote_value) can be either 1 or -1. Posts that have no vote (no row in msgboard_vote) would preferably be summed up as 0 in the result, null would do it as well.

Been tinkering for several hours… :/
Would greatly appreciate some help on this 🙂

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:32:30+00:00Added an answer on June 4, 2026 at 5:32 am

    Avoid sub-selects in the selected columns and the WHERE clause, the optimizer doesn’t handle them well.

    SELECT p.post_id, p.user_id, u.username, 
       get_time_diff(p.date) as date, p.ip, p.text, 
       p.parent_post_id, p.approved AS posts,
    IFNULL(v.vote_count, 0) AS vote_count
    FROM msgboard_user u, msgboard_post p
    LEFT JOIN
    (SELECT post_id, COUNT(*) vote_count FROM msgboard_vote GROUP BY post_id) v
    ON p.post_id = v.post_id
    WHERE p.user_id = u.user_id
    AND p.approved = "yes"
    ORDER BY p.date DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been fiddling with WebGL lately, and have gotten a Collada reader working. Problem
I have been fiddling around with server side interceptors on CXF. But is seems
I have been fiddling with code to call a function with the name of
I Have been fiddling with this for hours. I can not get my text
Have been working on this question for a couple hours and have come close
I have been fiddling around with settings for a while, and cannot seem to
I have been fiddling with this for almost an hour and am getting nowhere.
I am just learning C# (have been fiddling with it for about 2 days
I have been working on an iPhone App for a couple of weeks now
I've been fiddling with some ASP.NET MVC3 solution structures and I have settled on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.