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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:30:19+00:00 2026-06-14T07:30:19+00:00

Ok I am really stuck. I have three tables as follows: table contracts contract_id

  • 0

Ok I am really stuck. I have three tables as follows:

table contracts

contract_id  |  hotel_id  |  start    |    end
---------------------------------------------------
    1              356     2012-12-12   2012-12-16   
    2              258     2012-12-12   2012-12-16   
    3              211     2012-12-12   2012-12-16   

table hotel_info

hotel_id  |  hotel_desc
------------------------------
   356           description 1
   258           description 2
   211           description 3

table rates

contract_id  |  hotel_id  |  book_date  |   rate   |   closed  
--------------------------------------------------------------
     1            258       2012-12-12     250.00        1
     1            258       2012-12-13     250.00        0
     1            258       2012-12-14     250.00        1
     1            258       2012-12-15     250.00        1

Now what I am trying to do is retrieve all the rows from contracts table between a certain date range that the user will input. As you can see the rates table is seperated by each individual date. I do not want to get any rows back if the rates associated to them have a 0. So for example if I wanted to get a rate for dates between 2012-12-14 and 2012-12-15 I would get a result. But if I searched for 2012-12-12 to 2012-12-14 I do not get a result. I dont know if this is mega confusing but here is the mysql I have so far, which is not working:

SELECT r.*, c.* FROM contracts AS c
INNER JOIN hotel_info AS r ON r.hotel_id = c.hotel_id
INNER JOIN rates AS ra ON ra.contract_id = c.contract_id AND ra.closed != 0
WHERE c.start <= '2012-12-12' AND c.end >= '2012-12-16' GROUP BY r.room_name

Any help on this would be so appreciated! Let me know if I am missing something. Thannks in advance!

  • 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-06-14T07:30:21+00:00Added an answer on June 14, 2026 at 7:30 am

    If I’m understanding this correctly, you only want to return data if the range of the associated rate records within the date range specified for the contract have a rate of 1. I think using NOT EXISTS might do what you want.

    SELECT r.*, c.* FROM contracts AS c
        INNER JOIN hotel_info AS r ON r.hotel_id = c.hotel_id
        INNER JOIN rates AS ra ON ra.contract_id = c.contract_id AND ra.closed != 0
    WHERE c.start >= '2012-12-12' AND c.end <= '2012-12-16' 
        AND NOT EXISTS 
         (
             SELECT
                 1
             FROM rates ira 
             WHERE ira.contract_id = ra.contract_id
                 AND ira.rate = 0
         )
    GROUP BY r.room_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize this question is pretty basic, but I'm really stuck. I have a
I have been stuck on this and don't really know how to go about
I am stuck with something quite simple but really annoying: I have an xml
I'm stuck on a problem I really don't know how to solve: I have
I'm stuck to figure out how to write a query. Basically I've three tables
I have a pointing stick module i had from a really old laptop. It
I'm really stuck on why the following code block 1 result in output 1
I'm really stuck trying to find out how to force a programmatic refresh of
I'm really stuck trying to use java wrapper library for opencv's cvMatchTemplate. See this
I am really hoping someone can help me out, because I'm really stuck on

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.