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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:16:37+00:00 2026-05-20T13:16:37+00:00

I have a query with a sum in it like this: SELECT Table1.ID, SUM(Table2.[Number1]

  • 0

I have a query with a sum in it like this:

SELECT
    Table1.ID, SUM(Table2.[Number1] + Table2.[Number2]) AS SumColumn
FROM         Table1 INNER JOIN
                      Table3 ON Table1.ID = Table3.ID 
                    INNER JOIN
                      Table2 ON Table3.ID = Table2.ID
WHERE     (Table2.[Something] = 'Whatever')

GROUP BY Table1.ID,  Table2.[Number1] , Table2.[Number2]

and it gives me a table like this:

ID  SumColumn
67  1
67  4
70  2
70  6
70  3
70  6
80  5
97  1
97  3

How can I make it give me a table like this, where the SumColumn is summed, grouped by the ID column?

ID   SumColumn
67   5
70   17
80   5
97   4

I cannot GROUP BY SumColumn because I get an error (Invalid column name ‘SumColumn’.) COALESCE doesn’t work either. Thanks in advance.

EDIT:

Just grouping by the ID gives me an error:

[Number1, Number2 and the other column names that I’m selecting] is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

EDIT 2

No idea why but just grouping by Table.ID now seems to work. Thanks to all who posted the correct answer, I wish I could tick them all!

  • 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-20T13:16:38+00:00Added an answer on May 20, 2026 at 1:16 pm

    Have you tried:

    SELECT
        Table1.ID, SUM(Table2.[Number1] + Table2.[Number2]) AS SumColumn
    FROM         Table1 INNER JOIN
                          Table3 ON Table1.ID = Table3.ID 
                        INNER JOIN
                          Table2 ON Table3.ID = Table2.ID
    WHERE     (Table2.[Something] = 'Whatever')
    GROUP BY Table1.ID
    

    I can’t see why the above wouldn’t work, unless you are not aliasing tables appropriately in the query, which is more of a syntax than logic mistake, but ‘wrong’ from the SQL engine’s perspective regardless. Whenever SQL code doesn’t work for me, I simplify ad nauseam my query until the reason for it failing becomes apparent. In that vein, I’d try:

    SELECT ID, SUM(sumCol) as SumColumn
    FROM (
        SELECT
            Table1.ID, (Table2.[Number1] + Table2.[Number2]) AS sumCol
        FROM         Table1 INNER JOIN
                              Table3 ON Table1.ID = Table3.ID 
                            INNER JOIN
                              Table2 ON Table3.ID = Table2.ID
        WHERE     (Table2.[Something] = 'Whatever')
    )
    GROUP BY Table1.ID
    

    … and I’d allow any errors that show up from the following (and nested query!) to inform my further investigation.

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

Sidebar

Related Questions

Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
So I have a SQL Query as Follows SELECT P.Date, P.CategoryName, P.ProductName, SUM(Quantity) Quantity,
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query on my database as such: SELECT * FROM expenses WHERE
I've noticed that a few Wordpress blogs have query statistics present in their footer
I have a query where I wish to retrieve the oldest X records. At
I have a query that is dynamically built after looking up a field list

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.