0

In my MySQL DB I've got one table storing date periods. Each period row has PSTART and PEND columns defining period start and period end dates. How to create a query which will check if one particular date is within any of these periods or not? Number of periods in not fixed!

sbrbot
  • 6,169
  • 6
  • 43
  • 74
  • Welcome to SO. [What have you tried...?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) Better yet, give us an [SSCCE](http://www.sscce.org/) – amaidment Jun 07 '12 at 22:26

2 Answers2

1
SELECT * FROM periods WHERE [a date] BETWEEN PSTART AND PEND
aknosis
  • 3,602
  • 20
  • 33
0

Based on your question so far, this should give you all rows where date is between PSTART and PEND - you can modify depending on your requirements for inclusivity/exclusivity:

SELECT * FROM table WHERE date>=PSTART AND date<=PEND
amaidment
  • 6,942
  • 5
  • 52
  • 88
  • That's exactly the same as query before using BETWEEN date1 AND date2 – sbrbot Dec 01 '12 at 18:07
  • @sbrbot - First, if you look at the timestamps, I posted my answer before Aknosis' - so it would be incorrect to describe his as 'before' mine. Second, they are not the same, since my answer allows you to control inclusivity/exclusivity of start and end dates. – amaidment Dec 03 '12 at 10:57