1

I have a two column with date (from, to) in date format (Y-m-d), and I need MySQL SELECT which returns a correct value:

eg. I have same events:

 1. 2015-07-10 to: 2015-07-25
 2. 2015-07-21 to: 2015-07-24
 3. 2015-07-19 to: 2015-08-01
 4. 2015-07-29 to: 2015-08-05
 5. 2015-08-05 to: 2015-08-06
 6. 2015-08-10 to: 2015-08-10

and I need all events which is between 2015-07-11 and 2015-07-21.

**expected results:** 
*1,2,3*

Thank you!

Ameya Deshpande
  • 3,580
  • 4
  • 30
  • 46

1 Answers1

1

For ID 2, ID 3 you can check with "Between". For ID 1 you have to check if:

  1. Is From lower/equal than my start point?
  2. Is To higher/equal than my end point?

With this two questions you ensure it is within your Range.

http://sqlfiddle.com/#!9/642fb7/1

Here you got an example. :)

SophieXLove64
  • 316
  • 1
  • 11