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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:39:20+00:00 2026-05-10T19:39:20+00:00

I have a table named Info of this schema: int objectId; int time; int

  • 0

I have a table named Info of this schema:

int objectId; int time; int x, y; 

There is a lot of redundant data in the system – that is, objectId is not UNIQUE. For each objectId there can be multiple entries of time, x, y.

I want to retrieve a list of the latest position of each object. I started out with this query:

SELECT * FROM Info GROUP BY objectId 

That got me just the kind of list I was looking for. However I want also to get just the latest times for each Object, so I tried:

SELECT * FROM Info GROUP BY objectId ORDER BY time DESC 

This gave me a time descended list of Infos. However, I don’t think it did what I want – that is return me the latest time, x, y for each object.

Can anyone imagine a query to do what I want?

Update I have tried the top three solutions to see how they perform against each other on a dataset of about 50,000 Infos. Here are the results:

-- NO INDEX: forever -- INDEX: 7.67 s  SELECT a.* FROM Info AS a   LEFT OUTER JOIN Info AS b ON (a.objectId = b.objectId AND a.time < b.time) WHERE b.objectId IS NULL;  -- NO INDEX: 8.05 s -- INDEX: 0.17 s  select a.objectId, a.time, a.x, a.y   from Info a,        (select objectId, max(time) time from Info group by objectId) b   where a.objectId = b.objectId and a.time = b.time;  -- NO INDEX: 8.30 s -- INDEX: 0.18 s  SELECT A.time, A.objectId, B.x, B.y FROM (    SELECT max(time) as time, objectId     FROM Info    GROUP by objectId ) as A  INNER JOIN Info B    ON A.objectId = b.objectId AND A.time = b.time; 

By a margin, it would seem where outperforms inner join.

  • 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-10T19:39:20+00:00Added an answer on May 10, 2026 at 7:39 pm

    One way is using a subquery.

    select distinct a.objectID, a.time, a.x, a.y   from Info a,        (select objectID, max(time) time from Info group by objectID) b   where a.objectID = b.objectID and a.time = b.time 

    EDIT: Added DISTINCT to prevent duplicate rows if one objectId has multiple records with the same time. Depends on your data if this is necessary, the question author mentioned there were many duplicate rows. (added by Tomalak)

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

Sidebar

Related Questions

I have a schema that looks like this User Id INT Username VARCHAR(100) Password
Lets say I have table named Place with columns: placeId int not null auto_increment,
I have a table named datas and I'm executing a query like this: SELECT
I have a table named size here, something like this: size id | size
i have a table named member_photos that stores member_id , photo_id , photo_dir and
I have a products schema and some tables there. Each table in products schema
Say I have one MySQL schema named srvconfig with a table named tbl_cfg with
I have a table named tbl_Subjects_Taken which lists all the subjects taken by the
I have a table named scores with the columns id and score . I
I have a table named stats player_id team_id match_date goal assist` 1 8 2010-01-01

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.