MySQL Forums
Forum List  »  Newbie

How to detect two overlapping date ranges with the same primary key?
Posted by: Montana Burr
Date: December 28, 2021 12:35PM

I have a table that looks kind of like this:

PKey StartDate EndDate
0 2016-01-01 2016-02-01
0 2016-01-31 2016-03-05
1 2016-01-21 2016-01-18
1 2016-01-19 2016-02-01

As you can see, there are two overlapping date ranges for PKey 0. I want to return the second one.

This query just returns rows that have two StartDates and EndDates that are exactly the same:

SELECT * FROM
productcosthistory t1
JOIN productcosthistory t2
ON t1.productId = t2.productID;

Options: ReplyQuote


Subject
Written By
Posted
How to detect two overlapping date ranges with the same primary key?
December 28, 2021 12:35PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.