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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:32:57+00:00 2026-05-11T08:32:57+00:00

Here is my scenario, I have query that returns a lot of fields. One

  • 0

Here is my scenario,

I have query that returns a lot of fields. One of the fields is called ID and I want to group by ID and show a count in descending order. However, since I am bringing back more fields, it becomes harder to show a true count because I have to group by those other fields. Here is an example of what I am trying to do. If I just have 2 fields (ID, color) and I group by color, I may end up with something like this:

ID COLOR COUNT

== ===== =====

2    red     10

3    blue     5

4    green   24

Lets say I add another field which is actually the same person, but they have a different spelling of their name which throws the count off, so I might have something like this:

ID COLOR NAME COUNT

== ===== ====== =====

2    Red    Jim      5

2    Red    Jimmy      5

3    Red    Bob      3

3    Red    Robert      2

4    Red    Johnny      12

4    Red    John      12

I want to be able to bring back ID, Color, Name, and Count, but display the counts like in the first table. Is there a way to do this using the ID?

  • 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-11T08:32:57+00:00Added an answer on May 11, 2026 at 8:32 am

    If you want a single result set, you would have to omit the name, as in your first post

    SELECT Id, Color, COUNT(*) FROM YourTable GROUP By Id, Color 

    Now, you could get your desired functionality with a subquery, although not elegant

    SELECT Id, Color Name, (SELECT COUNT(*)                          FROM YourTable                          Where Id = O.Id                              AND Color = O.Color                        ) AS 'Count' FROM YourTable O GROUP BY Id, Color, Name 

    This should work as you desire

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If the diagonal has at least one intersection with the… May 11, 2026 at 11:20 am
  • added an answer Since you need this behavior in the unload event, you… May 11, 2026 at 11:19 am
  • added an answer After further investigation, it appears that when any part of… May 11, 2026 at 11:19 am

Related Questions

Here's my scenario: I have a page containing several links; each link is meant
Here is my scenario. For the example lets say that I need to return
I tried to make the title as clear as possible... here is my scenario:
Here's the scenario. I'm debugging my own app (C/C++) which is using some library
My usage-scenario may seem a bit unusual, but here it is: When using vim
Here is my code, which takes two version identifiers in the form 1, 5,
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
Here is my current question: I'm guessing that my problem (described below) is being
here is my directory structure. /user/a /user/b /user/b inside folder a,b,c there is a
Here is my question, Would it be possible, knowing that classic asp support server-side

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.