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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:20:21+00:00 2026-05-18T07:20:21+00:00

Why Microsoft uses stupid examples with GroupBy clause only for one table? http://msdn.microsoft.com/en-us/library/bb896341.aspx And

  • 0

Why Microsoft uses stupid examples with GroupBy clause only for one table?

http://msdn.microsoft.com/en-us/library/bb896341.aspx

And why error is causing when i tried to Select some field that is not in GroupBy?
Error says that fields that is not in GroupBy clause doesn’t exist in current context.

using (Entities db = new Entities())
{
    var query = "SELECT RLS.RoleId, UIR.UserId, UIR.RoleId, USR.UserName FROM Entities.aspnet_Roles AS RLS " +
                 "INNER JOIN Entities.vw_aspnet_UsersInRoles AS UIR " +
                 "ON RLS.RoleId = UIR.RoleId " + 
                 "INNER JOIN Entities.aspnet_Users AS USR " + 
                 "ON UIR.UserId = USR.UserId " + 
                 //"GROUP BY RLS.RoleId"  // is uncomment - it says UserId doesn't exist in context
                 ;
    var x = new ObjectQuery<DbDataRecord>(query, db);
    var y = x.ToTraceString().Replace("\n", " ").Replace("\t", " ").Replace("\r", " ");
}

The same for LINQ:

var x = from RLS in db.aspnet_Roles
                        join URS in db.vw_aspnet_UsersInRoles
                        on RLS.RoleId equals URS.RoleId
                        join USR in db.aspnet_Users
                        on URS.UserId equals USR.UserId
                        group RLS by RLS.RoleId into GRP
                        select new
                        {
                            GRP.Key
                        };

The question is: how to select all fields and GroupBy selection by only one field?

Thanks in advance.

  • 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-18T07:20:22+00:00Added an answer on May 18, 2026 at 7:20 am

    All fields that are not in the GROUP BY clause have to be aggregate expressions such as AVG(...) or SUM(...) or MAX(...) etc.

    So this is wrong:

    SELECT RLS.RoleId, UIR.UserId, UIR.RoleId, USR.UserName
    (...)
    GROUP BY RLS.RoleId
    

    because the last three expressions in the SELECT should either be aggregated somehow or added to the GROUP BY clause.

    This is logical because by specifying GROUP BY RLS.RoleId you say that RLS.RoleId should be unique in the end result, so only one row per value. But for each RLS.RoleID there could be multiple values for UIR.UserId, UIR.RoleId or USR.UserName. So you need to tell the DBMS what to do to make them into one row: average, maximum, minimum… OR you add fields to the GROUP BY clause, so that not RLS.RoleID but the combination of column values should be unique. See also this example.

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

Sidebar

Related Questions

I understand that Microsoft uses this template when versioning their products: Major.Minor.Build.Revision. Major is
We have an application that works with MS Office and uses Microsoft.mshtml.dll. We use
Has anyone successfully implemented a Java based solution that uses Microsoft SQL Server 2005
I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the
I am currently trying to build on TeamCity, which uses Microsoft.Office.Interop dll. This will
There is an application where I work that uses the Microsoft XML parser 3.0.
We've got a product that uses a Microsoft SQL Server database. We've got customers
I'm evaluating Microsoft Team Foundation Server for my customer, who currently uses Visual SourceSafe
Microsoft recently announced that the Javascript/HTML DOM library jQuery will be integrated into the
My program uses Microsoft RPC for interprocess communications. To prepare for receiving RPC calls

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.