I am trying to make a simple reservation system. I have a table called reservation that holds reservation time, and id of the customer who reserved it (see below for schema). And I have another table room, this table is for room types, so each type of room has an entry in this table for it's size and price. And another table rooms, for actual entry about each room. In the query I try to make, I want to select one room, that is of particular type, and that is available in the given time slice. Something like this;
Select number from rooms where type = 4 and available between $start-date and $end-date;
I couldn't figure out how to write available between part of the query. Relevant part of my schema follows;
CREATE TABLE IF NOT EXISTS `reservation` (
  `rid` int(11) NOT NULL AUTO_INCREMENT, /* reservation id */
  `number` int(11) NOT NULL, /* number of the room for this reservation */
  `cid` int(11) NOT NULL, /* customer id */
  `begin` date NOT NULL,
  `end` date NOT NULL,
  PRIMARY KEY (`rid`),
);
CREATE TABLE IF NOT EXISTS `room` (
  `rid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `size` tinyint(3) unsigned NOT NULL,
  `price` float NOT NULL,
  PRIMARY KEY (`rid`)
);
CREATE TABLE IF NOT EXISTS `rooms` (
  `number` smallint(5) unsigned NOT NULL,
  `type` int(11) NOT NULL,
  `available` tinyint(1) NOT NULL,
  `cid` int(11) DEFAULT NULL,
  PRIMARY KEY (`number`),
);