mysql - SQL - Check Availability -
i'm planning develop hotel management system each hotel has/have rate(s) particular set of days. rate values stored in table fine.
table below.

sql query use check whether there existing rates particular date range.
select * `hotel_rate` (from_date <= '2013-04-18' , to_date <= '2013-04-22') or (from_date >= '2013-04-18' , to_date >= '2013-04-22') or (from_date >= '2013-04-18' , to_date <= '2013-04-22') or (from_date <= '2013-04-18' , to_date >= '2013-04-22') what i'm trying add rate date range '2013-04-18' '2013-04-22'. there added rates date range '2013-04-20' '2013-04-23'. want inform administrator who's adding rates rates has been applied particular period he/she has selected.
the problem sql query fetch rows database want particular row(s) rates overlapped. in example result set should contain row has id = 4.
given according knowledge before adding rate should check below 4 conditions. 2 black lines show existing rates hotel. yellow lines show possible overlapping scenarios. in given set 1st yellow line from_date 2nd yellow line to_date.
how can fix ? how can overlapped rate row ?
i not quite sure if following, seems want determine if there records have kind of overlap 2 dates input. if case suggest this
select * `hotel_rate` from_date between ? , ? or to_date between ? , ? here of course, ? 2 dates. needs happen have overlap either from_date record or to_date record fall between input dates (input dates inclusive).
Comments
Post a Comment