'Select data from one table only with overlapping values
I need to get only the rows that overlap on Start an End
| Id | Start | End |
|---|---|---|
| 1 | 2 | 5 |
| 2 | 3 | 7 |
| 3 | 6 | 8 |
| 4 | 9 | 10 |
So the result will be
| Id | Start | End |
|---|---|---|
| 1 | 2 | 5 |
| 2 | 3 | 7 |
| 3 | 6 | 8 |
Solution 1:[1]
You could use exists logic along with the formula for the overlapping range problem:
SELECT *
FROM yourTable t1
WHERE EXISTS (
SELECT 1
FROM yourTable t2
WHERE t2.id <> t1.id AND t2.Start <= t1.End AND t2.End >= t1.Start
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
