I have a price_table, that has two columns: start_date and end_date (for promotional prices).
I'm trying to create a query that will check whether or not the given date range doesn't fall under another one that already exists.
I've been trying to use this query:
SELECT *
FROM tbl_preco
WHERE isActive = 1 AND (start_date between '2014-12-11 15:45:00' AND '2014-12-13 11:45:00'
OR end_date between '2014-12-11 15:45:00' AND '2014-12-13 11:45:00')
The problem is:
There's a promotional price from 2014-12-10 15:30:00
to 2014-12-13 14:30:00
, so neither of both BETWEEN instructions are catching it, even though the given range is in fact inside the range in the DB.
|------GIVEN RANGE-------|
|-------- RANGE IN DB --------|
The example above should be returned as TRUE, and the application will tell the user that there's already a promotional price within the given range.