TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mateusz TurismoGM
NA
22
4.8k
How to get all avaible rooms?
Feb 19 2016 8:36 AM
HI i have this SQL query to get all avaible rooms.
SELECT DISTINCT rooms.room_ID, room_number, room_floor, room_seats FROM rooms JOIN reservations
WHERE rooms.room_ID NOT IN (select room_ID from reservations)
OR reservations.room_ID=rooms.room_ID AND reservation_check_in NOT BETWEEN CAST('2016-02-15' AS DATE) AND CAST('2016-02-28' AS DATE)
AND reservation_check_out NOT BETWEEN CAST('2016-02-15' AS DATE) AND CAST('2016-02-20' AS DATE)
ORDER BY room_number
This query is working but only when is minimum one reservation in database. If there is no reservation, all rooms are avaible,
no matter what the date was given.
If(numberOfReservationsInDatabase == 0)
{
this query is not working(no rooms but
should in this case show all
rooms in database)
}
else if(numberOfReservationsInDatabase > 0)
{
this query is working(show only avaible rooms based on date)
}
How to change this query to work if(numberOfReservationsInDatabase == 0)?
Reply
Answers (
1
)
How to get 7 days before today date in mysql?
insert the split values into the same table.