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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:26:09+00:00 2026-06-18T08:26:09+00:00

How would I get one row out of two overlaping dates rows from the

  • 0

How would I get one row out of two overlaping dates rows from the same table for same id. I have more then 50000 records.

I have following sample data.

ID    start_dt    end_dt       division
1212  04/01/2006  03/01/2007   second
1212  05/01/2009  01/01/2010   second
1212  04/01/2006  03/01/2008   second   --- This should be selected as longest timeframe
1212  09/03/2007  03/01/2008   third
1213  05/03/2005  04/11/2009   second
1214  07/03/2007  03/01/2008   third

And the data I should get as following.

ID    start_dt    end_dt       division
1212  04/01/2006  03/01/2008   second
1212  05/01/2009  01/01/2010   second
1213  05/03/2005  04/11/2009   second
1214  07/03/2007  03/01/2008   third

Thank you.
Ramu

  • 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-18T08:26:10+00:00Added an answer on June 18, 2026 at 8:26 am

    Now that I understand your issue, just subtract the 2 dates to determine the time frame difference:

    SELECT S.Id, S.Start_dt, S.End_dt, S.Division
    FROM Sample S
     JOIN (
       SELECT S.Id, Max(S.end_dt-S.start_dt) as timeframe
    FROM Sample S
    GROUP BY S.Id ) S2 ON S.Id = S2.Id 
        AND S.end_dt-S.start_dt = s2.timeframe
    

    Here is the Fiddle.

    Good luck.

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

Sidebar

Related Questions

i would get details from two MySQL tables tables structure as shown table:App |AppID|AppName|AppType|
I have one query on which I would like to get your valuable feedback.
How would get find an average from an array? If I have the array:
What I have is a two tables. One table with users and another table
How would one get the contents of the 'value' attribute of a select tag,
I would like to get some feedback on what is one of my first
One obvious way to cause a stack overflow and get Segmentation fault would be
Following is how you would get the current solution directory from an add-in: _applicationObject
I'm looking for a way to select one table row explicitly for one thread.
In the following code, I have a div around each row in a table

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.