Consider the above relations. I'm trying to list all guests and dependants who are currently staying in the hotel, meaning they are present in the rooms.
Here is my SQL QUERY:
SELECT g.FORENAME, g.SURNAME
FROM GUEST g
INNER JOIN BOOKING b
ON g.GUESTID = b.GUESTID
WHERE (b.DEPARTDATE > TO_CHAR(CURRENT_DATE, 'DD-MON-YYYY') AND b.ARRIVEDATE < TO_CHAR(CURRENT_DATE, 'DD-MON-YYYY'))
UNION
SELECT d.FORENAME, d.SURNAME
FROM DEPENDANT d
INNER JOIN BOOKINGDEPENDANT bd
ON bd.DEPENDANTID = d.DEPENDANTID
WHERE bd.BOOKINGID IN (SELECT b.BOOKINGID
FROM BOOKING b
WHERE (b.DEPARTDATE > TO_CHAR(CURRENT_DATE, 'DD-MON-YYYY') AND b.ARRIVEDATE < TO_CHAR(CURRENT_DATE, 'DD-MON-YYYY')));
The query executes but displays no rows selected, when it is supposed to.
Here are my insert statements for BOOKING.
INSERT INTO BOOKING VALUES (2002, 5445, '19-MAR-2013', '10-JUN-2013', 250.00);
INSERT INTO BOOKING VALUES (2004, 3005, '19-MAR-2013', '21-MAR-2013', 250.00);
despite guest 5445 and 3005 meeting the where condition with their associated booking, no output is displaying. Im expecting the names of 5445 and 3005.
if I remove the below lines:
b.ARRIVEDATE < TO_CHAR(CURRENT_DATE, 'DD-MON-YYYY')
a list of names would be displayed. but the logic is wrong because without arrivedate consideration, you wouldnt be able to detect the present guests.
My question to you is the above line incorrectly added? why is it not displaying those guest when they meet the condition. they are the present guest after all. What can I do?