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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:33:57+00:00 2026-05-30T21:33:57+00:00

I know that the answer to this is going to be extremely simple and

  • 0

I know that the answer to this is going to be extremely simple and I’ve solved this problem before but for some reason I’ve been stuck on this for an hour.

I have the following query:

SELECT table1.FIELD1, table2.sum(FIELD2), table3.sum(FIELD3)
FROM (table1 INNER JOIN table2 ON table1.JOBINSTID = table2.JOBINSTID)
     INNER JOIN table3 ON table1.JOBINSTID = table3.JOBINSTID
GROUP BY FIELD1;

The results that it returns are totally bonkers. Instead of giving me the actual sum of Field2 it gives me a number WAYYY higher. I know why this is happening and somewhat understand it but I don’t know how to fix it. How do I change this query so that I get the correct sum?

EDIT: JOBINSTID is a unique ID in tables 1 and 2 but not in table 3.

  • 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-30T21:33:59+00:00Added an answer on May 30, 2026 at 9:33 pm

    If it’s only a many-to-one problem involving table1, you might want this:

    SELECT
      table2.FIELD1,
      SUM(table3.FIELD2)
    FROM table2 JOIN table3
    ON table3.JOBINST_ID = table2.JOBINSTID
    WHERE EXISTS (
      SELECT * FROM table1
      WHERE table1.JOBINSTID = table2.JOBINSTID
      -- AND table1.JOBINSTID = table3.JOBINST_ID -- redundant, but might improve runtime
    )
    GROUP BY table2.FIELD1;
    

    If the problem is (also) between table2 and table3, you may need to rethink how your database is normalized, but you could try this, which I think will work in any case:

    SELECT -- DISTINCT -- add DISTINCT if FIELD1 values are not unique in table2
      table2.FIELD1,
      (
        SELECT SUM(FIELD2) FROM table3
        WHERE table3.JOBINST_ID = table2.JOBINSTID
      )
    FROM table2
    WHERE EXISTS (
      SELECT * FROM table1
      WHERE table1.JOBINSTID = table2.JOBINSTID
    )
    

    Given what you’ve said, it’s hard to tell what you want, because you haven’t described which relationships are 1-1 and which are many-1, or indicated which columns are unique in which tables.

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

Sidebar

Related Questions

I know that this has already been asked here but the answer (using a
I have a feeling that I already know the answer to this one, but
I know this shouldn't be that hard, but I couldn't find the answer on
This is a question that I've always wanted to know the answer, but never
I know that this question might have been asked like 100 times, but, believe
I know this question has been asked before, but none of the existing SO
I know this type of question has been asked before, but I could not
I know there is a question about that, but there isn't any good answer(for
I know that there are a few questions like this on SOF, but I
We all know that 42 is the answer to everything , but it's news

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.