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 7886021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:13:02+00:00 2026-06-03T05:13:02+00:00

When I run this query, the votes sum is 2 times what it should

  • 0

When I run this query, the votes sum is 2 times what it should be (sum=6 instead of 3). Can someone figure out the fix for this?

SELECT sum(votes.vote) AS sum
    , my_votes.vote IS NOT NULL AS did_i_vote
    , votes.parent_id, subject
    , review_date
    , item_id
    , review_summary
    , review, full_name
    , reputation
    , profile_picture
    , accounts.acct_id
FROM votes
RIGHT JOIN items_purchased 
    on votes.parent_id=items_purchased.purchase_id 
JOIN accounts 
    ON items_purchased.purchaser_account_id=accounts.acct_id  
JOIN items 
    on items_purchased.item_id=items.folder_id
LEFT JOIN votes AS my_votes 
    ON my_votes.parent_id=items_purchased.purchase_id 
    AND my_votes.acct_id='3' 
    AND my_votes.column_name='purchase_id' 
WHERE purchase_id='2' 
    AND deleted_p!=1 and pub_priv_p!=1                                       
GROUP BY items_purchased.purchase_id

I’m pretty sure it has to do with the JOINs because if I get rid of JOIN items on items_purchased.item_id=items.folder_id then the sum=3. However, I need that JOIN in there somehow.

Thoughts?

  • 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-03T05:13:03+00:00Added an answer on June 3, 2026 at 5:13 am

    Without a schema we can’t tell, but this is a guess:

    Check all of your join conditions – you’re likely missing a condition causing that set of results to be ‘duplicated’.

    For example, if I have a table

    `Foo` with columns `A` `B` and `C` - A and B are the PK;
    `Bar` with columns `A` `B` and `Z` - A and B are the PK;
    `Biz` with columns `Z` `GOAL` 
    

    And I wanted to count the number of GOALS per A, if I joined the Foo to Bar just using A and not B as well, I would likely get an erroneous count.

    The easiest way to see this is to do a SELECT * and remove the group by

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

Sidebar

Related Questions

When I run this query: select First_Name, sum(a) a, sum(b) b, sum(c) c from
When I run this query It works SELECT sum( amount ) AS balance FROM
If I try to run this query in SQL Server 2005: SELECT 1 WHERE
If I run this query: SELECT `Manga`.`id`, `Manga`.`name` FROM `mangas` AS `Manga` WHERE `Manga`.`id`
Here is my example. When I run this query: SELECT SUBSTRING('Lorem ipsum dolor sit
i run this query in SQL Server 2008 declare @a varchar(1) select @a =
I'm unable to run this query, where can be the error, because it's ok.,
I'm trying to run this query: SELECT Destaque.destaque, Noticia.id, Noticia.antetitulo, Noticia.titulo, Noticia.lead, Noticia.legenda, Noticia.publicacao,
When I run this query ` SELECT id FROM bckoff WHERE left = 3;
I am trying to run this query: $record = Doctrine_Query::create() ->select('m.*') ->from('Modification m') ->leftJoin('m.Location

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.