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 1116169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:15:45+00:00 2026-05-17T03:15:45+00:00

I have above mysql table with available dates and prices. Second table includes room

  • 0

alt text

I have above mysql table with available dates and prices. Second table includes room details. How can I join two tables to get available rooms between two dates and not get duplicate content.

  • 1 1 Answer
  • 0 Views
  • 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-17T03:15:46+00:00Added an answer on May 17, 2026 at 3:15 am

    This is hard to come up with a complete answer for you here, as you are only showing us the table which contains the bookings – we cannot know what range of rooms are available.

    SQL which returns the room_id’s for rooms which are booked for at least part of the selected period could be:

    SELECT `room_id` , COUNT(*)
    FROM `bookings`
    WHERE `dt` BETWEEN "[start date]" AND "[end date]"
    GROUP BY `room_id`;
    

    If you had a table of rooms (rather than bookings), it would be possible for you to return a list of any rooms not booked during that period with:

    SELECT `id`
    FROM `rooms`
    WHERE `id` NOT IN (
      SELECT DISTINCT( `room_id` )
      FROM `bookings`
      WHERE `dt` BETWEEN "[start date]" AND "[end date]"
    );
    

    AMENDMENT

    Based on the feedback by OP, the assumptions are now:

    • The table contains details of rooms which are available for a period starting on the date in column dt and ending the following day (ie hotel rooms)
    • The query should return any rooms which are available for the entirity of the period entered (so only rooms which are available from DAY A to DAY B will be returned.

    As such, the amended code is:

    SELECT room_id
    FROM available_rooms
    WHERE dt BETWEEN "[start date]" AND DATE_SUB("[end date]",INTERVAL 1 DAY)
    GROUP BY room_id
    HAVING COUNT(*)=ABS(DATEDIFF("[start date]","[end date]"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to delete orphan entries in a mysql table. I have 2 tables
I have a mysql table of the following structure. So the above table stores
I have a Mysql table where it combines three tables. This table stores some
I have a mysql table, each row of which can have an arbitrary number
I have two column in my mysql table A and B and I am
I am stuck with a mysql query. I have three tables: Table Name :
I have a mySQL table with records of users who have visited my site.
I have a mysql table called pollOfTheWeek. It has a column pollDate of type
I have a MySQL table setup as follows: +---------------+-------------+------+-----+---------+----------------+ | Field | Type |
I have a MySQL table containing phone numbers that may be formatted in many

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.