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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:04:51+00:00 2026-05-21T18:04:51+00:00

I hope someone can help me with my MySQL problem. I have a bug

  • 0

I hope someone can help me with my MySQL problem. I have a bug where if there is one left outer join on contribution table, result of amount is $100 (which is correct). If I include a second left outer join of another table (ikes). And I have 2 ikes, it doubles amount ($200), if I have 3 ikes, it triples ($300). For the life of me, I cannot figure this out. What do the ikes have any to do with the contribution amount? I’ve separated the queries and they work by themselves. But together they cause the problem.

Can anyone see the problem? I’ve included the query and the tables below.

         SELECT COUNT(i.type) AS xlike, 
                SUM(c.amount) AS amount, 
                w.* 
           FROM wish w 
LEFT OUTER JOIN contributions c ON w.ID=c.receiveid
LEFT OUTER JOIN ikes i ON w.ID=i.wishid 
          WHERE w.ID = 236

Tables:

CREATE TABLE IF NOT EXISTS `contributions` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `amount` decimal(19,2) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

CREATE TABLE IF NOT EXISTS `ikes` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `type` enum('likes','dislikes') NOT NULL,
  `wishid` int(11) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
  • 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-21T18:04:52+00:00Added an answer on May 21, 2026 at 6:04 pm

    While most will tell you to use JOINs, you have to be aware that joins will duplicate parent records if more than one child record is associated to it. This is what can inflate values from aggregate functions.

    I re-wrote your query as:

       SELECT w.*,
              COALESCE(x.amount, 0) AS amount,
              COALESCE(y.type, 0) AS type
         FROM WISH w 
    LEFT JOIN (SELECT c.receiveid,
                      SUM(c.amount) AS amount
                 FROM CONTRIBUTIONS c
             GROUP BY c.receiveid) x ON x.receiveid = w.ID
    LEFT JOIN (SELECT i.wishid,
                      COUNT(i.type) AS type
                 FROM IKES i
             GROUP BY i.wishid) y ON y.wishid = w.ID
        WHERE w.ID = 236
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope someone can help me out. I have a table that logs our
I hope someone can help me since I have no clue whats going on
I hope someone can help... This issue has been discussed here and I have
I have a problem with CodeIgniter .htaccess file and hope that somebody can help
hope someone can help. I appreciate there are a few questions that are similar
I hope i can get a help from someone. I have an asp.net application
hope someone can help me on this as been stuck for hours. I am
I hope someone can help us. We’re trying to put together an image editor,
Hi i hope someone can help, In basic terms i am trying to stop
I am stuck in a predicament whereby I hope someone can help me. I

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.