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

  • SEARCH
  • Home
  • 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 7569067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:04:48+00:00 2026-05-30T15:04:48+00:00

The following query used to grab all comments for a particular blog article and

  • 0

The following query used to grab all comments for a particular blog article and worked well. I’ve now added a members reputation point system to my blog, similar to Stack Overflow’s reputation system, and tried modifying this query to get the reputation points from the members_reputation table, to display next to the user’s name on each comment.

I thought by adding SUM(rep.points) AS member_rep and adding a LEFT JOIN on the reputation table would do the trick but I’m getting strange results, too strange to describe. Actually, one funny behaviour is that not all the comments are being returned. Where if I removed my attempted solution, all comments are returned but I need to count/show their reputation.

Every comment has a member and every member has reputation.

SELECT comment.comment_id, comment.member_id, comment.comment,
comment.posted, member.screen_name, member.country_code, SUM(rep.points) AS member_rep
FROM blog_comments AS comment
LEFT JOIN members AS member ON comment.member_id = member.member_id

// my attempt start //
LEFT JOIN members_reputation AS rep ON comment.member_id = rep.member_id
// my attempt end //

WHERE comment.article_id = "&article_id&"
ORDER BY comment.comment_id DESC

DB Structure

comments              :    comment_id, member_id, comment, posted
members               :    member_id, screen_name, country_code
members_reputation    :    member_id, activity_type, points

What I want to see

This is a posted comment on my blog. Cool huh?
25/02/2012 By Martin G **850** (GBR)

If anyone can help me get back on the right road, I would be very grateful…

  • 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-05-30T15:04:49+00:00Added an answer on May 30, 2026 at 3:04 pm

    Here’s a couple of things I noticed.

    First, your where clause is asking for comment.article_id, which you haven’t included in your table structure at the bottom of your post. I’m going to make the assumption that you just left it out, but thought I’d point it out anyways.

    You can also simplify your joins by specifying USING instead of ON if the column name is the same in both tables.

    Another thing to consider is the type of relationship you have between the tables. If it’s a one to one relationship than joins are simple. If it’s a one to many or many to many than joins get more complicated and you have to GROUP them together properly. I’m going to assume that each comment has only one member, and every member may have more than one rep.

    Finally, you have a column that shares a name with a table alias (comment). This can lead to problems, if your sql syntax even allows it.

    This is what I’d use, myself:

    SELECT c.comment_id, c.member_id, c.comment, c.posted, m.screen_name, m.country_code
           SUM(r.points) `member_rep`
    FROM blog_comments `c`
    LEFT JOIN members `m` USING (member_id)
    LEFT JOIN members_reputation `r` USING (member_id)
    WHERE c.article_id = "&article_id&"
    ORDER BY c.comment_id DESC
    

    Also: what does the “&article_id&” represent?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the following query is used in my Wordpress blog, it gets the categories that
Following query is used for Getting Categories and one news for each category. How
The following query was successful when I used in mysql INSERT INTO user(`dev_id`,`email`) VALUES('123','456@gmail.com');
I have written the following query, but in the WHERE clause I have used
The following code is used in a query for fetching records. It uses the
Problem is with the following query. I want to list all the LI:s in
i have used the following query for POPUP LOV in Apex select VEN_INVOICE_REFNO as
I have the following query in access used in a report for data selection.
How I can rewrite following query that I will take minus Correction and Used
The following query used to work: select * from information_schema.columns where column_name like ...

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.