2 years ago
#22011
rainbem
Get all rows that overlaps dates
Question
I have a table that holds all the work experience of each employee. I want to get all work experience of employee that overlapped the dates. Below is the sample.
Scenario
Employee 1 have a total of two (2) work experience. Employee 2 have a total of three (3) work experience.
tbl_work_exp
employee_id | start_date | end_date |
---|---|---|
1 | 2021-01-01 | 2021-06-30 |
1 | 2021-07-01 | 2021-12-31 |
2 | 2021-01-01 | 2022-02-01 |
2 | 2021-07-01 | 2021-12-31 |
2 | 2022-01-01 | present |
3 | --- | --- |
4 | --- | --- |
5 | --- | --- |
and so on... |
The first row of Employee 2 overlap the dates to its present work experience.
What I need is to get all rows that overlap the dates, like the table below.
Results
employee_id | start_date | end_date |
---|---|---|
2 | 2021-01-01 | 2022-02-01 |
2 | 2021-07-01 | 2021-12-31 |
2 | 2022-01-01 | present |
Thank you in advance.
mysql
date
select
overlap
0 Answers
Your Answer