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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:51:14+00:00 2026-06-01T11:51:14+00:00

I’ve successfully merged 3 tables (using ID’s), but when I try to add 4th

  • 0

I’ve successfully merged 3 tables (using ID’s), but when I try to add 4th table – output completely messes up (values become unrealistic/wrong) so I think that I has something to do with the fact, that this 4th table has ungrouped ID’s, so I need to group them before Joining this new table. Right now the query is following:

SELECT name, SUM(money) AS MONEY
FROM transactions
JOIN results ON transactions.id = results.id
JOIN more ON results.per_id = more.per_id
GROUP BY name
HAVING SUM(money)>500

and when I join new table:

SELECT name, SUM(money) AS MONEY, SUM(data_from_NT1), SUM(data_from_NT2)
FROM transactions
JOIN results ON transactions.id = results.id
JOIN more ON results.per_id = more.per_id

JOIN newtable ON results.per_id = newtable.per_id

GROUP BY name
HAVING SUM(money)>500

is it possible to execute a command GROUP BY per_id:

(JOIN newtable ON results.per_id = newtable.per_id GROUP BY per_id)

before adding this new table into the main table? The line from above doesn’t work.

  • 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-01T11:51:15+00:00Added an answer on June 1, 2026 at 11:51 am

    Yes, it is possible, but you have to write it as a SELECT. This is a first version of a possible answer:

    SELECT name,
           SUM(money)             AS money,
           SUM(nt2.data_from_NT1) AS data_from_NT1,
           SUM(nt2.data_from_NT2) AS data_from_NT2
      FROM transactions AS t
      JOIN results      AS r ON t.id = r.id
      JOIN more         AS m ON r.per_id = m.per_id
      JOIN (SELECT per_id, SUM(data_from_NT1) AS data_from_NT1, SUM(data_from_NT2) AS data_from_NT2
              FROM newtable GROUP BY per_id
           ) AS nt2 ON results.per_id = nt2.per_id
     GROUP BY name
    HAVING SUM(money) > 500;
    

    It isn’t completely clear whether you need the ‘SUM of SUMs’ in the main select-list; you probably don’t. It also isn’t clear where the name or money columns come from; I’d normally prefix them with the appropriate table alias, too. With those caveats, this might be more nearly what you’re after:

    SELECT name, SUM(money) AS MONEY, nt2.data_from_NT1, nt2.data_from_NT2
      FROM transactions AS t
      JOIN results      AS r ON t.id = r.id
      JOIN more         AS m ON r.per_id = m.per_id
      JOIN (SELECT per_id, SUM(data_from_NT1) AS data_from_NT1, SUM(data_from_NT2) AS data_from_NT2
              FROM newtable GROUP BY per_id
           ) AS nt2 ON results.per_id = nt2.per_id
     GROUP BY name, nt2.data_from_NT1, nt2.data_from_NT2
    HAVING SUM(money) > 500;
    

    There are undoubtedly other ways to write this. The grouping in the main query might be better put into a parallel sub-query, leaving simple direct joins in the main query. But we don’t have the information to actually do that for you.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.