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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:18:33+00:00 2026-05-25T22:18:33+00:00

I am having a trouble in querying my database.. I have a table :

  • 0

I am having a trouble in querying my database.. I have a table :

**Room**
 +----------------------------------+
 |RoomNo---RoomStatusID---RoomTypeID|
 |  1   ---     1      ---    1     |
 |  2   ---     1      ---    1     |
 +----------------------------------+

**ClientRoom**
 +--------------------------------------------------------------------+
 |ClientRoomNo---RoomNo--------ArrivalDate-------------DepartureDate  |
 |  1         ---  1   ---- 2011-10-03 1:00:00 ---- 2011-10-03 4:00:00|
 |  2         ---  1   ---- 2011-10-03 5:00:00 ---- 2011-10-03 8:00:00|
 +--------------------------------------------------------------------+

If I use this query =

SELECT Room.RoomNo, RoomType.RoomType
FROM Room INNER JOIN
RoomType ON Room.RoomTypeNo = RoomType.RoomTypeNo
FULL OUTER JOIN ClientRoom ON Room.RoomNo = ClientRoom.RoomNo
WHERE
(((ClientRoom.ArrivalDate <= '10-03-2011 1:00:00' AND
ClientRoom.ArrivalDate <= '10-03-2011 5:00:00') AND
(ClientRoom.DepartureDate <= '10-03-2011 1:00:00' AND
ClientRoom.DepartureDate <= '10-03-2011 5:00:00'))
OR Room.RoomStatusId  = 1)

It would return

**ClientRoom**
     +--------------------------------------------------------------------+
     |ClientRoomNo---RoomNo--------ArrivalDate-------------DepartureDate  |
     |  2         ---  1   ---- 2011-10-03 5:00:00 ---- 2011-10-03 8:00:00|
     +--------------------------------------------------------------------+

Because it reached up to 5:00am in the morning.
But when I change the Arrival and Departure to.. 5:00 – 8:00..
RoomNo 1 is still in the results.
I already tried NOT BETWEEN 🙁

  • 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-25T22:18:34+00:00Added an answer on May 25, 2026 at 10:18 pm

    You did not explain what result you want in what circumstances. But this condition

    ClientRoom.ArrivalDate <= '10-03-2011 1:00:00' AND 
    ClientRoom.ArrivalDate <= '10-03-2011 5:00:00'
    

    looks fishy, because the first part is redundant. You could simply say

        ClientRoom.ArrivalDate <= '10-03-2011 5:00:00'
    

    Same thing for the next part:

    ClientRoom.DepartureDate <= '10-03-2011 1:00:00' AND
    ClientRoom.DepartureDate <= '10-03-2011 5:00:00'
    

    This is the same as just saying:

    ClientRoom.DepartureDate <= '10-03-2011 5:00:00'
    

    Edit: From the comments I read it, that you have a given timespan (a,d) and want to check for each row, if your timespan overlaps with the timespan of the row (A,D). You want to see only non-overlapping rows.

    This means your WHERE clause must be like this quasicode:

    WHERE d <= A -- my departure will be before the rows arrival
       OR a >= D -- my arrival is behind the rows departure
    

    In full terms:

    WHERE (    '10-03-2011 5:00:00' <= ClientRoom.ArrivalDate 
            OR '10-03-2011 1:00:00' >=  ClientRoom.DepartureDate 
          )
        OR Room.RoomStatusId = 1
    

    Edit 2:

    What does the query with this fixes? “Show me all schedule rows, which do not conflict with my schedule.” But the query should be “Show me the rooms which do not have any conflicts with my schedule.” That is a completely different beast but easily translated into SQL:

    SELECT 
        Room.RoomNo
    FROM Room
    WHERE NOT EXISTS (
        SELECT 1 
        FROM ClientRoom
        WHERE 
           Room.RoomNo = ClientRoom.RoomNo
           AND (   '10-03-2011 5:00:00' <= ClientRoom.ArrivalDate 
                OR '10-03-2011 1:00:00' >=  ClientRoom.DepartureDate 
               )
    )
    OR Room.RoomStatusId  = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble querying my SQLite database using Android. I keep getting either an
I seem to be having trouble querying my 'events' table which contains foreign keys.
I'm having some trouble parsing malformed XML in PHP. In particular I'm querying a
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I having trouble in dividing the HTML frames. I have been using the following
Having trouble getting this to work. What's strange is that I have 10 bookmarks
I am having trouble inserting values into my Account table that's in a SQL
I've been having trouble querying a web server for information from my Windows Phone
I'm having trouble querying for supported languages using the SpeechRecognizer.ACTION_GET_SUPPORTED_LANGUAGES. private void queryLanguages() {
Having trouble with grepping and cutting at the same time I have a file

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.