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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:54:34+00:00 2026-05-15T07:54:34+00:00

Ok, so I have a table Table: Id Value If I query my table

  • 0

Ok, so I have a table

Table:
Id
Value

If I query my table and group my result by “Value” how can I make it so each of the groups are alphabetized (a group grouped by a “Value”=”a” will come before a group grouped by a “Value” = “z”).

My current query looks something like this:
var Result = 
from a in DB.Table
orderby a.Value
group by a.Value into b
select new {Groupz = b};
  • 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-15T07:54:34+00:00Added an answer on May 15, 2026 at 7:54 am

    The other answers are ordering the initial list and then ordering the groups. This works because GroupBy preserves the order of the initial collection. However, if you want to actually order the groups (which was the original question), you want to create the groups first, and then order by the Key of the IGrouping object:

        [Test]
        public void Test()
        {
            var collection = new List<Fake>()
                                 {
                                     new Fake {Value = "c"},
                                     new Fake {Value = "b"},
                                     new Fake {Value = "a"},
                                     new Fake {Value = "a"}
                                 };
            var result =
                collection.GroupBy(a => a.Value, a => a).OrderBy(b => b.Key).ToList();
    
            foreach(var group in result)
            {
                Console.WriteLine(group.Key);
            }
        }
    
        private class Fake
        {
            public string Value { get; set; }
        }
    

    Using query syntax, this looks like this:

            var result =
                from a in collection
                group a by a.Value
                into b
                orderby b.Key
                select b;
    

    Again, we’re doing the group by operation before the order by operation, and actually performing the ordering on the group, not on the original list elements.

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

Sidebar

Related Questions

I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
I have iterated a table based on my query result... I have a column
I have a problem with an SQL query. SELECT SUM(table_colum) AS value, SUM(value *
I have used a join query for retrieving value from two tables one is
I have the following query: INSERT INTO table (a, b, c) VALUES (NOW(), NOW()
We have a table value function that returns a list of people you may
Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
Let's say I have the following table: Value Time 0 15/06/2012 8:03:43 PM 1
Below I have table - Company id name value year 1 IBM 10 2011
Lets say I have table with ID int, VALUE string: ID | VALUE 1

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.