mysql - SQL select the available rooms by date cheking -


i have in database table called rooms contain rooms information , property ,and table called reservation table contain room reserved, fromdate , todate .

what want make user pick room size want reserve , pick date reserving room ,then provide him available rooms depend on room reservation table.

here did:

select  * rooms,reservations  rooms.r_size = 'roomsize' , ('4/19/2013' not  between reservation.fromdate , reservation.todate  , '4/19/2013' not between reservation.fromdate , reservation.todate)  

the problem return me duplicate's rooms , if between reserved date in specific reservation not between reserved date in reservation still return me.

what want check if room reserved @ same or between specif date , if don't want selected , returned @ all.

thanks.. , sorry poor english

there 2 problems query. 1 there no condition on join between rooms , reservations, such rooms of correct size returned once each reservation satisfying date tests. problem date test wrong not detect existing reservations within date interval of new reservation.

a query 1 should give result want:

select * rooms left join reservations  on reservations.r_number = rooms.number , reservations.todate > '4/19/2013' , reservations.fromdate < '4/20/2013' rooms.r_size = 'roomsize'  , reservations.r_number null  

it works joining rooms reservations room, , selecting rooms there no reservations conflicts new reservation being made.(old reservation ends before new 1 starts, or starts after new 1 ends no problem).


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -