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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:16:45+00:00 2026-06-09T06:16:45+00:00

I would prefer to use a JOIN for this, but none of the solutions

  • 0

I would prefer to use a JOIN for this, but none of the solutions are either viable due to performance impacts or they don’t return the right result set.

The RunTime column is a UNIX timestamp captured every night at midnight. Not every entry will occur every night, meaning an entry for Entry1 may have occurred two days ago, but not today.

Schema:

 `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `Name` varchar(32) NOT NULL,
  `Category` int(11) NOT NULL,
  `RunTime` int(11) NOT NULL,
  UNIQUE KEY `ID` (`ID`),

Example Desired Results:

+-------------+----------------+----------+
| Name        | LastRunTime        | Count    |
+-------------+----------------+----------+
| Random Name |     1339131600 |       73 |
| RandomName2 |     1337131600 |       13 |
... etc

Essentially, my working query looks like the below. It will query the table for yesterdays data.

select Name,
       RunTime AS LastRunTime,
       count(*) AS Count
from TABLE
where RunTime = 
    (
    select DISTINCT( RunTime ) from TABLE WHERE r.Name=Name order by RunTime LIMIT 1,1
    ) 
and Category in 
    (
    select AnotherTable .ID from AnotherTable where AnotherTable.Status = 1
    )

group by Name

The problem is, this query is slow. I want to move away from the first subquery, on the RunTime column, but the LIMIT and association is getting the best of me. The above takes a very, very, long time.

Does anyone have an example of a way to:

Get the second most recent RunTime, the count of rows for the second most recent RunTime, quickly and efficiently where RunTime is not consistent across all rows?

Any suggestions are appreciated!

  • 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-09T06:16:47+00:00Added an answer on June 9, 2026 at 6:16 am

    I stuck with a subquery but changed the timeframe to WHERE RunTime = (SELECT MAX(RunTime) - 86400....

    All other solutions or attempts where either too demanding or convoluted.

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

Sidebar

Related Questions

I don't want to use sendmail to send an email but would prefer to
Which version would you prefer? #!/usr/bin/env perl use warnings; use strict; use 5.010; my
My customer doesn't want a database but would prefer to update their data in
I would like to plot a vertical line (I'd prefer any orientation, but I'd
I would prefer to use what I already have and just add an image
I need help with an nhibernate query. I would prefer to use Criteria API
I do all of my terminal work in emacs and would prefer to use
I have a website where I would prefer to use &shy ; (soft hyphen)
I see this scattered throughout code base: @RequestMapping(value = myValue) I would prefer to
It doesn't seem that PHP is short on XML-RPC solutions. I would prefer to

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.