0

Table:

id | u_id | start_date |  end_date  |
-------------------------------------
01 |   7  | 2015-05-05 | 2015-07-23 |
02 |   4  | 2015-07-10 | 2015-07-15 |
03 |   4  | 2015-08-27 | 2015-11-05 |
04 |   5  | 2015-08-01 | 2015-12-09 |

Need these rows:

03 |   4  | 2015-08-27 | 2012-11-05 |
04 |   5  | 2015-08-01 | 2012-12-09 |

input data that I have for query: start_date = 2015-10-01 and end_date = 2015-10-31

amdixon
  • 3,814
  • 8
  • 25
  • 34
ptenchik0
  • 57
  • 1
  • 6

1 Answers1

2

Try this:

SELECT id, u_id, start_date, end_date 
FROM mytable
WHERE start_date <= @end_date AND end_date >= @start_date

The above will return all records whose start_date - end_date interval overlaps with @start_date - @end_date.

Demo here

Giorgos Betsos
  • 71,379
  • 9
  • 63
  • 98