I need to select rows with start and end dates and if some dates overlap check if the rest of the row is the same then merge the rows with min(startdate) and max(startdate)? I think I first need to group rows that overlap and then I can do a group by that.
Each row have an ID, start_date, end_date and some data. Some rows date range overlaps and some don't, I want to merge those that have the same ID, data and have a date range that overlaps.
When tried only the two top rows with the suggested answer I got the three rows that are last in the question.
id valid_from valid_to
900101 06-MAY-13 02-FEB-14
900101 03-FEB-14 23-JUL-14
900102 01-JAN-10 01-DEC-10
900102 01-JAN-11 23-JAN-13
900102 01-AUG-11 23-JAN-15
900102 01-SEP-11 15-DEC-14
After a run it should be:
id valid_from valid_to
900101 06-MAY-13 02-FEB-14
900101 03-FEB-14 23-JUL-14
900102 01-JAN-10 01-DEC-10
900102 01-JAN-11 23-JAN-15
Where the three bottom rows merged.
With only the two top rows the suggested code returned this:
900101 06-MAY-13 02-FEB-14
900101 06-MAY-13 23-JUL-14
900101 03-FEB-14 23-JUL-14