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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:50:01+00:00 2026-06-15T03:50:01+00:00

I have a table: Group | BasalArea | SpeciesName 1 | 3.6 | Palustris

  • 0

I have a table:

Group | BasalArea | SpeciesName
1     | 3.6       | Palustris
1     | 45.0      | MSO
2     | 4.2       | Oak
2     | 2.0       | MSO
...

From this table, I would like to get the species name with the highest basal area grouped by the Group field, which would look like this:

Group | BasalArea | SpeciesName
1     | 45.0      | MSO
2     | 4.2       | Oak

Using SQL, I can get the highest basal area:

SELECT Group, Max(BasalArea)
FROM TABLE
GROUP BY Group

I can’t figure out how to also get the species name without doing some looping. Is this possible? What are the strategies for handling ties?

  • 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-06-15T03:50:02+00:00Added an answer on June 15, 2026 at 3:50 am

    This is simpler in LINQ2SQL than in SQL:

    var res = source.MyTable
        .GroupBy(item => item.Group)
        .Select(g => g.OrderByDescending(item => item.BasalArea).First())
        .ToList();
    

    This will return the list of items with largest values of BasalArea in its Group, together with SpeciesName.

    In SQL you would need to join back to the original table, like this:

    SELECT * FROM TABLE b
    JOIN (
        SELECT Group, Max(BasalArea) as BasalArea
        FROM TABLE
        GROUP BY Group
    ) t on t.Group = b.Group AND t.BasalArea = b.BasalArea
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like this: name code group john 12 smith 15 how
I have a table that looks like this Group Recipe Priority 0 A 400
I have a table like this one: id group value 1 GROUP A 0.641028
I have a table like this: |sub_account|name|email| |-----------|----|-----| // same account and same name:
I have table like this: Name Result T1 fail T2 pass T3 pass T2
I have this table : I would like to delete same rows. For example
If I have a table like this: ID | Name | Age 1 |
suppose I have SELECT * FROM table t GROUP BY j HAVING condition_one OR
I have a table that includes some student group name, lesson time, day names
I have a SqlServer2005 table Group similar to the following: Id (PK, int) Name

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.