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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:11:07+00:00 2026-06-17T02:11:07+00:00

I have a collection content that has four columns; id , timestamp , locationID

  • 0

I have a collection content that has four columns; id, timestamp, locationID, and authorID. Here is an example of my data; in production, this is tens of millions of rows in length.

id    timestamp              locationID   authorID
1     2012-03-01 11:52:00    1            1
2     2012-03-16 19:56:00    1            2
3     2012-04-02 11:26:00    2            1
4     2012-04-22 11:52:00    2            3
5     2012-05-19 09:48:00    2            2
6     2012-05-30 07:12:00    2            1
7     2012-06-04 19:17:00    1            2

I’d like to collect the list of authorIDs whose most recent content (ordered by timestamp) matched a specific locationID.

The correct values for a query of locationID = 2 would be: [ 1, 3 ], as authorID 1 and 3 were most recently ‘seen’ at locationID = 2, while authorID 2’s most recent content was at locationID 1.

I can certainly execute one query per authorID, but on production the authorID array has a length >100,000. This seems terribly inefficient (especially when each ‘subquery’ would be hitting this multi-million row content collection), and I’m looking for a better way to emerge this data from my dataset, ideally fast enough to be executed on a page render.

  • 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-17T02:11:08+00:00Added an answer on June 17, 2026 at 2:11 am

    Something like this? This is from SQL Server, but I think it should work in mySQL as well.

    DECLARE @locationId INT
    SET @locationId = 2;
    
    SELECT * 
    FROM (SELECT AuthorId, Max(TimeStamp) as MaxTimeStamp
        FROM Content C
        WHERE LocationId = @locationId
        GROUP BY AuthorId) AS CBL
        LEFT JOIN Content AS C ON CBL.AuthorId = C.AuthorId
            AND C.TimeStamp > CBL.MaxTimeStamp
    WHERE C.AuthorId IS NULL
    

    For locationId = 2, it returns 1 and 3; and for locationId = 1, it returns 2

    Per JW (thanks!), the correct mySql approach:

    SET @locationId := 2;
    
    SELECT * 
    FROM (SELECT AuthorId, Max(TimeStamp) as MaxTimeStamp
        FROM Content C
        WHERE LocationId = @locationId
        GROUP BY AuthorId) AS CBL
        LEFT JOIN Content AS C ON CBL.AuthorId = C.AuthorId
            AND C.TimeStamp > CBL.MaxTimeStamp
    WHERE C.AuthorId IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
Using a jQuery effect, I have a layer that has a collection of HTML
I have a DataGrid that has AutoGenerateColumns=True. I'm binding that DataGrid to a collection
I have a content type that has a lookup field for a document library
If I wanted to have a collection that described the (recursive) contents of a
I have a custom control with a public collection marked as DesignerSerializationVisibility.Content . When
I have Collection List<Car> . How to compare each item from this collection with
I have an ASP.NET web app that retrieves a JSON collection and outputs the
Okay i have a custom server control that has some autocomplete settings, i have
I have XML that looks like this <xml> <news> <newsitem> <publishdate>2011-10-11</publishdate> <title>Article 1</title> <breakingnewsflag>false</breakingnewsflag>

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.