I have a working reservation query. This query checks which items are available for the time of reservation.
[PROJECT]: projectid, datefrom, dateto, …
[ITEM]: itemid, itemgroupid, …
[ITEMGROUP]: itemgroupid, itemgroupname, …
[RESERVELIST]: itemid, projectid, reservelistnr
SELECT *
FROM item i inner join itemgroup ig on i.itemgroupid = ig.itemgroupid
WHERE i.itemid NOT IN (
SELECT r.itemid
FROM reservelist r inner join project p on r.projectid = p.projectid
WHERE p.datefrom BETWEEN '$datefrom' AND '$dateto'
OR p.dateto BETWEEN '$datefrom' AND '$dateto'
OR '$datefrom' BETWEEN p.datefrom AND p.dateto
OR '$dateto' BETWEEN p.datefrom AND p.dateto
)
ORDER BY itemid
$datefrom and $dateto are the dates of the time of reservation.
Now this query works well, but if someone make a reservation between 08:00 – 21:00, the next reservation can only be done at 21:01 and not at 21:00 sharp. So I need to have a smaller than and greater than.
I played alot with the < and >, but somehow it doesn’t seem to work.
My best guess is that this should be the good solution:
SELECT *
FROM item i inner join itemgroup ig on i.itemgroupid = ig.itemgroupid
WHERE i.itemid NOT IN (
SELECT r.itemid
FROM reservelist r inner join project p on r.projectid = p.projectid
WHERE p.datefrom > '$datefrom' AND p.datefrom < '$dateto'
OR p.dateto > '$datefrom' AND p.dateto < '$dateto'
OR '$datefrom' > p.datefrom AND '$datefrom' < p.dateto
OR '$dateto' > p.datefrom AND '$dateto' < p.dateto
)
ORDER BY itemid
Unfortunately, it isn’t.
Anyone any idea?
Works.