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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:25:00+00:00 2026-05-11T00:25:00+00:00

This has bugged me for a long time. 99% of the time, the GROUP

  • 0

This has bugged me for a long time.

99% of the time, the GROUP BY clause is an exact copy of the SELECT clause, minus the aggregate functions (MAX, SUM, etc.).
This breaks the Don’t Repeat Yourself principle.

When can the GROUP BY clause not contain an exact copy of the SELECT clause minus the aggregate functions?

edit

I realise that some implementations allow you to have different fields in the GROUP BY than in the SELECT (hence 99%, not 100%), but surely that’s a very minor exception?
Can someone explain what is supposed to be returned if you use different fields?

Thanks.

  • 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. 2026-05-11T00:25:01+00:00Added an answer on May 11, 2026 at 12:25 am

    I tend to agree with you – this is one of many cases where SQL should have slightly smarter defaults to save us all some typing. For example, imagine if this were legal:

    Select ClientName, InvoiceAmount, Sum(PaymentAmount) Group By * 

    where ‘*’ meant ‘all the non-aggregate fields’. If everybody knew that’s how it worked, then there would be no confusion. You could sub in a specific list of fields if you wanted to do something tricky, but the splat means ‘all of ’em’ (which in this context means, all the possible ones).

    Granted, ‘*’ means something different here than in the SELECT clause, so maybe a different character would work better:

    Select ClientName, InvoiceAmount, Sum(PaymentAmount) Group By ! 

    There are a few other areas like that where SQL just isn’t as eloquent as it could be. But at this point, it’s probably too entrenched to make many big changes like that.

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

Sidebar

Related Questions

This has bugged me for a long time, and try as I might I
This one has bugged me for the longest time and a great question to
This has bugged me several time. I am debugging a custom subview for example.
This problem has bugged me so many times and i have now decided to
One of the things that has long bugged me about the FileSystemWatcher is the
This has always bugged the hell out of me. Why are lists like this?
Well,This thing has bugged me for days. I have developed an app that checks
The lack of expression trees in Compact Framework has bugged me for some time
This has bugged me for years but I cannot find anything about it in
This has confused and bugged me for a few years, thought I would open

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.