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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:42:03+00:00 2026-05-11T02:42:03+00:00

I have data that looks like this: entities id name 1 Apple 2 Orange

  • 0

I have data that looks like this:

entities id         name 1          Apple 2          Orange 3          Banana 

Periodically, a process will run and give a score to each entity. The process generates the data and adds it to a scores table like so:

scores  id  entity_id    score   date_added 1    1            10       1/2/09 2    2            10       1/2/09 3    1            15       1/3/09 4    2            10       1/03/09 5    1            15       1/4/09 6    2            15       1/4/09 7    3            22       1/4/09 

I want to be able to select all of the entities along with the most recent recorded score for each resulting in some data like this:

entities id name     score  date_added 1  Apple     15     1/4/09 2  Orange    15     1/4/09 3  Banana    15     1/4/09 

I can get the data for a single entity using this query:

SELECT entities.*,         scores.score,         scores.date_added  FROM entities  INNER  JOIN scores ON entities.id = scores.entity_id  WHERE entities.id = ?  ORDER BY scores.date_added DESC LIMIT 1 

But I’m at a loss for how to select the same for all entities. Perhaps it’s staring me in the face?

Thank you very kindly for taking the time.

Thanks for the great responses. I’ll give it a few days to see if a preferred solution bubbles up then I’ll select the answer.

UPDATE: I’ve tried out several of the proposed solutions, the main issue I’m facing now is that if an entity does not yet have a generated score they don’t appear in the list.

What would the SQL look like to ensure that all entities are returned, even if they don’t have any score posted yet?

UPDATE: Answer selected. Thanks everyone!

  • 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-11T02:42:04+00:00Added an answer on May 11, 2026 at 2:42 am

    I do it this way:

    SELECT e.*, s1.score, s1.date_added  FROM entities e   INNER JOIN scores s1     ON (e.id = s1.entity_id)   LEFT OUTER JOIN scores s2     ON (e.id = s2.entity_id AND s1.id < s2.id) WHERE s2.id IS NULL; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SQL data that looks like this: events id name capacity 1 Cooking
I have YAML data that looks sort of like this, but ~150k of it:
I have data that looks like this Investor Contact IBM James IBM Dean IBM
I have a data that looks like this: 1 1:-0.394668 2:-0.794872 3:-1 4:-0.871341 5:0.9365
I have data that looks like CUSTOMER, CUSTOMER_ID, PRODUCT ABC INC 1 XYX ABC
I have a list of data that looks like the following: // timestep,x_position,y_position 0,4,7
I have code that looks like: //System.Data.IDataRecord dr try { Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
My application I have an application design that looks like this: web application layer
I have an NHibernate entity that looks like this: public class Offender { public
I have a costumer showing Notepad with a large set of data that looks

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.