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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:49:18+00:00 2026-05-25T20:49:18+00:00

We have timestamps for various things across the site. I’m looking for a way

  • 0

We have timestamps for various things across the site. I’m looking for a way to get users who are “online” or have been active in the past 20 minutes. Im also trying to sort them by an intersection of the latest timestamp in multiple columns across multiple tables.

SELECT user.userID, user.username, GREATEST(
     (SELECT MAX(notifications.noteTime) FROM notifications WHERE notifications.creatorID = user.userID),
     challengesRead.lastRead,
     notificationsRead.lastRead) AS realtime
 FROM user
 LEFT JOIN challengesRead ON challengesRead.userID = user.userID
 LEFT JOIN notificationsRead ON notificationsRead.userID = user.userID
 LEFT JOIN notifications ON notifications.creatorID = user.userID
 LEFT JOIN challenges ON challenges.userID = user.userID
 WHERE timestampdiff(minute, realtime, now()) < 20
 GROUP BY user.userID
 ORDER BY realtime DESC

My questions.

1) Timestampdiff doesn’t seem to recognize realtime? However, recalculating GREATEST() in timestampdiff does work but seems repetitive.

2) Yikes, this beast takes forever to run, whats the best way to optimize?

3) What is a better way to do this?

  • 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-05-25T20:49:18+00:00Added an answer on May 25, 2026 at 8:49 pm

    you could make a new table like ‘latest_activity’ and add triggers to populate with user_id and timestamp… that would at least give you one place to query.

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

Sidebar

Related Questions

There have been various similar questions, but they either referred to a too specific
I have been working on Neural Networks for various purposes lately. I have had
I have been testing the accuracy of various aspects of CoreLocation and have been
Is it a good practice to have timestamps for the last row update in
I want to copy files that have timestamps from the time the script begins
Given that I have 2 timestamps: 1332954000 which is 18:00pm in human readable format.
I have a database which is going to have UMT timestamps in standard sql
The log4j logs I have contain timestamps in the following format: 2009-05-10 00:48:41,905 I
Is it possible to have microsecond level timestamps in log4j logging? This is on
The underlying problem - let's say my documents have categories and timestamps . If

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.