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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:28:08+00:00 2026-05-26T12:28:08+00:00

I have to comapre the results relative to the same time between two tables,

  • 0

I have to comapre the results relative to the same time between two tables, but the time stamps differs of some second because of how they were recorded.
I would like to obtain a result like in Example 1 but I get only the values with the asterisk, as in Example 2.
What is the best way to remove the secods from the comparison, or to select the value corresponding to the closest DATETIME value?

Currently I’m using this query:

SELECT Table1.TimeSTamp1, Table1.Param1, Table2.TimeStamp2, Table2.Param2 
    FROM Table1, Table2 
    WHERE ... conditions for the other parameters of Table1 and Table2... 
    AND Table1.TimeSTamp1 = Table2.TimeStamp2

Any suggestion on the best practice is warmly welcomed.


Example 1

TimeStamp1          ¦   Param1  ¦   TimeStamp2          ¦   Param2
2011-01-01 00:00:35 ¦   1       ¦   2011-01-01 00:00:35 ¦   a       *
2011-01-01 00:01:35 ¦   2       ¦   2011-01-01 00:01:35 ¦   b
2011-01-01 00:02:37 ¦   3       ¦   2011-01-01 00:02:35 ¦   c
2011-01-01 00:03:31 ¦   4       ¦   2011-01-01 00:03:35 ¦   d
2011-01-01 00:04:32 ¦   5       ¦   2011-01-01 00:04:35 ¦   e
2011-01-01 00:05:38 ¦   6       ¦   2011-01-01 00:05:35 ¦   f
2011-01-01 00:06:36 ¦   7       ¦   2011-01-01 00:06:36 ¦   g       *
2011-01-01 00:07:32 ¦   8       ¦   2011-01-01 00:07:35 ¦   h
2011-01-01 00:08:33 ¦   9       ¦   2011-01-01 00:08:35 ¦   i
2011-01-01 00:09:33 ¦   10      ¦   2011-01-01 00:09:33 ¦   l       *
2011-01-01 00:10:35 ¦   11      ¦   2011-01-01 00:10:35 ¦   m       *
2011-01-01 00:11:29 ¦   12      ¦   2011-01-01 00:11:31 ¦   n

lll
Example 2

TimeStamp1          ¦   Param1  ¦   TimeStamp2          ¦   Param2
2011-01-01 00:00:35 ¦   1       ¦   2011-01-01 00:00:35 ¦   a
2011-01-01 00:06:36 ¦   7       ¦   2011-01-01 00:06:36 ¦   g
2011-01-01 00:09:33 ¦   10      ¦   2011-01-01 00:09:33 ¦   l
2011-01-01 00:10:35 ¦   11      ¦   2011-01-01 00:10:35 ¦   m
  • 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-26T12:28:08+00:00Added an answer on May 26, 2026 at 12:28 pm

    This MySql expression will give you back DATETIME values with the seconds zeroed out.

    CONVERT(DATE_FORMAT(table.column,'%Y-%m-%d-%H:%i:00'),DATETIME)
    

    Take a look at this. https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format . So you might end up with a query like this:

    SELECT Table1.TimeSTamp1, Table1.Param1, Table2.TimeStamp2, Table2.Param2 
        FROM Table1
        JOIN Table2 ON  CONVERT(DATE_FORMAT(Table1.TimeStamp1,'%Y-%m-%d-%H:%i:00'),DATETIME)
                     =  CONVERT(DATE_FORMAT(Table2.TimeStamp2,'%Y-%m-%d-%H:%i:00'),DATETIME)
        WHERE ... conditions for the other parameters of Table1 and Table2... 
    

    But, be careful. Autogenerated timestamps are kind of like floating point numbers; when two of them turn up equal to each other it’s just luck. Truncating your timestamps to the minute may be OK, but you may also be better off subtracting one timestamp from another, and comparing the differences (or the absolute values of the differences).

    Also, this join is going to be slow because it has to run the second-truncating function on every value, so it can’t use any indexes.

    You can subtract one timestamp from another with TIMESTAMPDIFF(). But be careful. This function only works correctly at the level of seconds for timestamps within a few days of each other; it overflows gracelessly (as I discovered with great pain).

    You could try truncating the timestamps to minutes at the time you insert them. That would let you index them.

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

Sidebar

Related Questions

With the arima function I found some nice results, however now i have trouble
I have two tables Temporal_Group and Product_Group If I perform the following query to
I have 2 files that contain benchmark results for the same test on 2
I am trying to compare 2 strings but getting weird results. On some computers,
I have a project where I need to compare multi-chapter documents to a second
I have two dates: how do I compare which one is greater date in
Here's the question : I have 2 tables , one containing the base data
I have created a quiz app which emails the user the results. I want
I have a table of results I'd like to display: | change | position
I have an application that takes the quality results for a manufacturing process and

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.