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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:05:21+00:00 2026-05-10T17:05:21+00:00

Not sure how to ask a followup on SO, but this is in reference

  • 0

Not sure how to ask a followup on SO, but this is in reference to an earlier question: Fetch one row per account id from list

The query I’m working with is:

SELECT * FROM scores s1 WHERE accountid NOT IN (SELECT accountid FROM scores s2 WHERE s1.score < s2.score) ORDER BY score DESC 

This selects the top scores, and limits results to one row per accountid; their top score.

The last hurdle is that this query is returning multiple rows for accountids that have multiple occurrences of their top score. So if accountid 17 has scores of 40, 75, 30, 75 the query returns both rows with scores of 75.

Can anyone modify this query (or provide a better one) to fix this case, and truly limit it to one row per account id?

Thanks again!

  • 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-10T17:05:22+00:00Added an answer on May 10, 2026 at 5:05 pm

    If you’re only interested in the accountid and the score, then you can use the simple GROUP BY query given by Paul above.

    SELECT accountid, MAX(score)  FROM scores  GROUP BY accountid; 

    If you need other attributes from the scores table, then you can get other attributes from the row with a query like the following:

    SELECT s1.* FROM scores AS s1   LEFT OUTER JOIN scores AS s2 ON (s1.accountid = s2.accountid      AND s1.score < s2.score) WHERE s2.accountid IS NULL; 

    But this still gives multiple rows, in your example where a given accountid has two scores matching its maximum value. To further reduce the result set to a single row, for example the row with the latest gamedate, try this:

    SELECT s1.* FROM scores AS s1   LEFT OUTER JOIN scores AS s2 ON (s1.accountid = s2.accountid      AND s1.score < s2.score)   LEFT OUTER JOIN scores AS s3 ON (s1.accountid = s3.accountid      AND s1.score = s3.score AND s1.gamedate < s3.gamedate)  WHERE s2.accountid IS NULL     AND s3.accountid IS NULL; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • 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 You bet. The desirable thing about function programming is that… May 11, 2026 at 3:19 pm
  • added an answer I recently started to dabble in Mono myself and have… May 11, 2026 at 3:19 pm
  • added an answer First() and Last() are part of LINQ which is why… May 11, 2026 at 3:19 pm

Related Questions

I have a WinForms .NET app that, according to the Vista Task Manager with
I'm not sure how to ask this but here goes. I draw a filled
I'm not exactly sure how to ask this question really, and I'm no where
I'm not sure how to ask the question, for I don't know what I

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.