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

  • Home
  • SEARCH
  • 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 8772181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:58:43+00:00 2026-06-13T17:58:43+00:00

In the below i have a table1,table2 ,i am stuck with a query.I want

  • 0

In the below i have a table1,table2 ,i am stuck with a query.I want find the timestamps in table2 which are in between two consecutive timestamps of table1 .How to form this query.

table1:

   id    timestamp
    1    2012-08-15 01:11:11
    1    2012-08-15 01:11:14
    1    2012-08-15 01:11:16 
    2    2012-08-15 01:22:11
    2    2012-08-15 01:32:11
    2    2012-08-15 01:33:11
    2    2012-08-15 01:36:11

table 2:

   id    timestamp
    1    2012-08-15 01:11:12
    1    2012-08-15 01:11:15
    1    2012-08-15 01:11:16 
    2    2012-08-15 01:23:55
    2    2012-08-15 01:26:11
    2    2012-08-15 01:34:11
    2    2012-08-15 01:36:01

Desired output:Get all rows of table2 which are in between the timestamps of table1 and if possible output timestamp of table1 also

  • 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-13T17:58:44+00:00Added an answer on June 13, 2026 at 5:58 pm

    Join table1 to itself and then group to find consecutive timestamps, then join the result to table2 as desired:

    SELECT *
    FROM   table2 JOIN (
      SELECT   a.timestamp start, MIN(b.timestamp) finish
      FROM     table1 a JOIN table1 b ON a.timestamp < b.timestamp
      GROUP BY a.timestamp
    ) t ON table2.timestamp BETWEEN t.start AND t.finish
    

    See it on sqlfiddle.

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

Sidebar

Related Questions

I have the query below which works great. SELECT `Despatch`.`DespatchNumber` , `Despatch`.`Product` , `Stock`.`ProductNumber`
I am stuck on a LINQ query. Basically I have two tables linked by
I have created one table using the below command: create table Table1( Id int
I have the correlated subquery below. Each id (147,148,149) in table1 has many records
I have a table with a form below it. You can fill out the
I stuck on this, I want to create a table with 10 rows, each
I have two tables A and Band the relation between A to B is
I am stuck on an update query that is using a subquery and have
I have 2 main tables in My-SQL database. Table1 is -> Master Table2 is
This has had me stuck for a long time and I have tried several

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.