Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4253904
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:00:35+00:00 2026-05-21T05:00:35+00:00

(In case this seems familiar: I asked a different question similar to this one

  • 0

(In case this seems familiar: I asked a different question similar to this one, but I just got a note that the site design has changed and now the owners do want a way to search for any room that is available between a range of dates. So this is a new question…)

I’m working on a hotel reservation system and I need to find which rooms are available between a range of dates. The existing ‘availability’ table schema is simple, the columns are:

room_id
date_occupied - a single day that is occupied (like '2011-01-01')

So, if, for example, room #6 is occupied from January 1 to January 5, five rows are added to the availability table, one for each day that room is occupied.

I’m trying to figure out the query to find what rooms are available between a start and end date (while also filtering on some other parameters like non-smoking, bed size, etc.)… in pseudo-SQL it would be sort of like:

SELECT (a list of room IDs) FROM rooms, availability
 WHERE rooms.nonsmoking = 1
   AND rooms.singlebed = 1
   AND nothing between start_date and end_date is in availability.date_occupied

As with my other question, I’m a bit stuck trying to determine the exact query and how to join the tables it in the most efficient way. Thanks for the help.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:00:36+00:00Added an answer on May 21, 2026 at 5:00 am

    If I understood your db structure properly, you need to find a row in rooms with no corresponding rows in availability.

    SELECT r.* 
    FROM rooms r
      LEFT JOIN availability a ON (r.id = a.room_id 
     AND a.date_occupied BETWEEN :start_date AND :end_date)
    WHERE a.id IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this seems to be hundred times answered question, but I can't find a working
So I have a Rails app (which in this case seems like it would
It may be the case this is only possible through looping, but who knows.
Consider this case: public Class1 { public static final String ONE = ABC; public
Imagine this case, but with a lot more component buckets and a lot more
This might be a bit of hasty conclusion, but my question arose when I
This would seem to be the case in Firefox 3.5+, there I can instantiate
This case is a bit complex, I hope I will simplify it well. My
In this case the character is ^ . For example in the following format
In this case, the source of the text is from a winforms textbox. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.