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
  • 1 View
  • 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

Related Questions

Sorry but I am not sure how to ask this question but I am
Im not even sure how to ask this question, but i'll give it a
I'm not really sure how to ask this question, but I'll do my best.
This question not probably not typical stackoverflow but am not sure where to ask
Not sure if this is an appropriate forum to ask this question, but I've
Not sure whether to ask this question here but here is the question. What
Not sure how to ask this question, but here goes. Say I have: var
Am not sure how to ask this question but for most of you more
I'm not sure how to ask this question, but here goes... I am rendering
I'm really not sure how to ask this question but I need a way

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.