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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:17:02+00:00 2026-05-23T11:17:02+00:00

Suppose I have a table with 3 columns: id (PK, int) timestamp (datetime) title

  • 0

Suppose I have a table with 3 columns:

  • id (PK, int)
  • timestamp (datetime)
  • title (text)

I have the following records:

1, 2010-01-01 15:00:00, Some Title
2, 2010-01-01 15:00:02, Some Title
3, 2010-01-02 15:00:00, Some Title

I need to do a GROUP BY records that are within 3 seconds of each other. For this table, rows 1 and 2 would be grouped together.

There is a similar question here: Mysql DateTime group by 15 mins

I also found this: http://www.artfulsoftware.com/infotree/queries.php#106

I don’t know how to convert these methods into something that will work for seconds. The trouble with the method on the SO question is that it seems to me that it would only work for records falling within a bin of time that starts at a known point. For instance, if I were to get FLOOR() to work with seconds, at an interval of 5 seconds, a time of 15:00:04 would be grouped with 15:00:01, but not grouped with 15:00:06.

Does this make sense? Please let me know if further clarification is needed.

EDIT: For the set of numbers, {1, 2, 3, 4, 5, 6, 7, 50, 51, 60}, it seems it might be best to group them {1, 2, 3, 4, 5, 6, 7}, {50, 51}, {60}, so that each grouping row depends on if the row is within 3 seconds of the previous. I know this changes things a bit, I’m sorry for being wishywashy on this.

I am trying to fuzzy-match logs from different servers. Server #1 may log an item, “Item #1”, and Server #2 will log that same item, “Item #1”, within a few seconds of server #1. I need to do some aggregate functions on both log lines. Unfortunately, I only have title to go on, due to the nature of the server software.

  • 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-23T11:17:02+00:00Added an answer on May 23, 2026 at 11:17 am

    I’m using Tom H.’s excellent idea but doing it a little differently here:

    Instead of finding all the rows that are the beginnings of chains, we can find all times that are the beginnings of chains, then go back and ifnd the rows that match the times.

    Query #1 here should tell you which times are the beginnings of chains by finding which times do not have any times below them but within 3 seconds:

    SELECT DISTINCT Timestamp
    FROM Table a
    LEFT JOIN Table b
    ON (b.Timestamp >= a.TimeStamp - INTERVAL 3 SECONDS
        AND b.Timestamp < a.Timestamp)
    WHERE b.Timestamp IS NULL
    

    And then for each row, we can find the largest chain-starting timestamp that is less than our timestamp with Query #2:

    SELECT Table.id, MAX(StartOfChains.TimeStamp) AS ChainStartTime
    FROM Table
    JOIN ([query #1]) StartofChains
    ON Table.Timestamp >= StartOfChains.TimeStamp
    GROUP BY Table.id
    

    Once we have that, we can GROUP BY it as you wanted.

    SELECT COUNT(*) --or whatever
    FROM Table
    JOIN ([query #2]) GroupingQuery
    ON Table.id = GroupingQuery.id
    GROUP BY GroupingQuery.ChainStartTime
    

    I’m not entirely sure this is distinct enough from Tom H’s answer to be posted separately, but it sounded like you were having trouble with implementation, and I was thinking about it, so I thought I’d post again. Good luck!

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

Sidebar

Related Questions

Suppose I have a table with the columns: `id`,`firstname`,`lastname` With some rows like: '1','bob','marley'
Suppose I have a table Orders in sql with 4 columns (OrderId int, ProductID
Suppose I have the following tables: CREATE TABLE Game ( GameID INT UNSIGNED NOT
Suppose I have a database table with columns a, b, and c. I plan
Suppose I have a tags table with two columns: tagid and contentid . Each
Suppose I have two columns in a table that represents a graph, the first
Suppose I have a table amountInfo with columns (id, amount1, amount2, amount3) where amountX
I have created table #temp with columns id as int identity(1,1) and name as
I have a table with four columns, say P_Key(int), Ref_Key(int), Key(String), Value(Integer). I want
Suppose I have this database table (some sample code below) that stores the relationship

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.