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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:56:28+00:00 2026-05-29T06:56:28+00:00

When I run a query using group by … with rollup : select a,

  • 0

When I run a query using group by ... with rollup:

select a, b, sum(c) 
from <table> 
group by a, b with rollup;

I get duplicate rows in (what I consider to be) the PK of the query (that is, the group-by columns):

+------+------+--------+
| a    | b    | sum(c) |
+------+------+--------+
| NULL | NULL |     13 |
| NULL |    1 |      4 |
| NULL |    3 |      8 |
| NULL |    4 |      9 |
| NULL | NULL |     34 |
|    1 |    3 |     17 |
|    1 |    4 |   NULL |
|    1 |   17 |      2 |
|    1 | NULL |     19 |
|    2 | NULL |      6 |
|    2 |    1 |     17 |
|    2 |    3 |     17 |
|    2 | NULL |     40 |
|    4 |   17 |      2 |
|    4 | NULL |      2 |
|    5 | NULL |     11 |
|    5 |    6 |      7 |
|    5 | NULL |     18 |
|   13 |    4 |      2 |
|   13 | NULL |      2 |
|   14 |   41 |      3 |
|   14 | NULL |      3 |
|   18 |    1 |      2 |
|   18 | NULL |      2 |
|   41 |    2 |     17 |
|   41 | NULL |     17 |

… more rows follow …

How do I distinguish (NULL, NULL, 13) from (NULL, NULL, 34)? That is, how do I distinguish between the row that has nulls because of the underlying data, and the row that has nulls because it was added by rollup? (Note that there are more examples — (2, NULL, 6) and (2, NULL, 40))

  • 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-29T06:56:29+00:00Added an answer on May 29, 2026 at 6:56 am

    Good question. One option I can think of is to do this:

    select COALESCE(a, -1) AS a, COALESCE(b, -1) AS b, sum(c) 
    from <table> 
    group by COALESCE(a, -1), COALESCE(b, -1) with rollup;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run the query : select count(*) from (select idCover from x90..dimCover group
If I run a query such as: SELECT COUNT(*) as num FROM table WHERE
I am using Oracle 11.1.0.6.0 and ADO.NET (System.Data.OracleClient) to run a query that works
I am using in C# MYsql .I have query that works if I run
Looking to run a query using multiple left joins. The following query works. SELECT
I am using this awesome code from @Richard aka cyberkiwi to run a query
I have a query that is getting counts from multiple tables by using a
Let's say I have this, that produces 50,000 rows: SELECT photoID FROM photoSearch WHERE
In my repository implementation I can run the following query using a lambda expression:
I am looking into using only a ddl to run my query, not a

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.