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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:58:45+00:00 2026-06-10T21:58:45+00:00

There is a table with the columns : USE ‘table’; insert into person values

  • 0

There is a table with the columns :

USE 'table';  
insert into person values   
('11','xxx','1976-05-10','p1'),  
('11','xxx ','1976-06-11','p1'),  
('11','xxx ','1976-07-21','p2'),  
('11','xxx ','1976-08-31','p2'),  

Can anyone suggest me a query to get the start and the end date of the person with respect to the place he changed chronologically.

The query I wrote

SELECT PId,Name,min(Start_Date) as sdt, max(Start_Date) as edt, place 
from ** 
group by Place;

only gives me the first two rows of my answer. Can anyone suggest the query??

  • 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-10T21:58:46+00:00Added an answer on June 10, 2026 at 9:58 pm

    This isn’t pretty, and performance might be horrible, but at least it works:

    select min(sdt), edt, place
    from (
      select A.Start_Date sdt, max(B.Start_Date) edt, A.place
      from person A
           inner join person B on A.place = B.place
                              and A.Start_Date <= B.Start_Date
           left join person C on A.place != C.place
                             and A.Start_Date < C.Start_Date
                             and C.Start_Date < B.Start_Date
      where C.place is null
      group by A.Start_Date, A.place
    ) X
    group by edt, place
    

    The idea is that A and B represent all pairs of rows. C will be any row in between these two which has a different place. So after the C.place is null restriction, we know that A and B belong to the same range, i.e. a group of rows for one place with no other place in between them in chronological order. From all these pairs, we want to identify those with maximal range, those which encompass all others. We do so using two nested group by queries. The inner one will choose the maximal end date for every possible start date, whereas the outer one will choose the minimal start date for every possible end date. The result are maximal ranges of chronologically subsequent rows describing the same place.

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

Sidebar

Related Questions

Let's say we have a table with columns DAY and NUMERO. There can be
There is a table with columns ID Number and date, .. The problem: how
Basically if I had a mysql table with columns: id, type, content, version. There
i have a t_class table in mySql, in this table there are 3 columns,
Is there a way to return all the columns in a MySQL table in
I have a table in which there are two columns : 1. import type,
I've got a table in which there are some columns with big text data.
I've got a mysql table of 'events' with columns for 'category' and 'visited'. There's
I have a table ProductNumberDuplicates_backups, which has two columns named ProductID and ProductNumber. There
I am creating a calendar application. In the Events table, there are two columns,

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.