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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:51:23+00:00 2026-06-17T15:51:23+00:00

can anyone help me with my sql statement below. What i am trying to

  • 0

can anyone help me with my sql statement below. What i am trying to do is retrieve rows from 1 table where they do not appear within the date range of another table. The query below at the moment returns the row that is between the date range entered. How could i modify it so that the rows not between the date range in table 2 are returned from table 1? table 1 would be homes and table 2 would be bookings

SELECT homes.home_id, homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft,
listagg(features.feature_name, '\n') WITHIN GROUP(ORDER BY features.feature_name) features, home_type.type_name
FROM homes
INNER JOIN bookings ON bookings.home_id = homes.home_id
INNER JOIN home_feature ON homes.home_id = home_feature.home_id
INNER JOIN home_type ON home_type.type_code = homes.type_code
INNER JOIN features ON home_feature.feature_id = features.feature_id
WHERE bookings.booking_end < to_date('23-Jan-13')
OR bookings.booking_start > to_date('22-Jan-13')
GROUP BY homes.home_id, homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft, home_type.type_name
  • 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-17T15:51:24+00:00Added an answer on June 17, 2026 at 3:51 pm

    You will want to use a LEFT JOIN to return all rows from homes that do not appear in bookings. I would also suggest moving the bookings.date filter from the WHERE clause to the JOIN condition:

    SELECT homes.home_id, 
        homes.title, 
        homes.description, 
        homes.living_room_count, 
        homes.bedroom_count, 
        homes.bathroom_count, 
        homes.price, homes.sqft,
       listagg(features.feature_name, '\n') WITHIN GROUP(ORDER BY features.feature_name) features, 
        home_type.type_name
    FROM homes
    LEFT JOIN bookings 
       ON bookings.home_id = homes.home_id
       AND (bookings.booking_end < to_date('23-Jan-13')
        OR bookings.booking_start > to_date('22-Jan-13'))
    LEFT JOIN home_feature 
      ON homes.home_id = home_feature.home_id
    LEFT JOIN home_type 
      ON home_type.type_code = homes.type_code
    LEFT JOIN features 
      ON home_feature.feature_id = features.feature_id
    GROUP BY homes.home_id, homes.title, 
        homes.description, homes.living_room_count, 
        homes.bedroom_count, homes.bathroom_count, 
        homes.price, homes.sqft, home_type.type_name
    

    Based on your comment, you can try a NOT EXISTS:

    SELECT homes.home_id, 
        homes.title, 
        homes.description, 
        homes.living_room_count, 
        homes.bedroom_count, 
        homes.bathroom_count, 
        homes.price, homes.sqft,
       listagg(features.feature_name, '\n') WITHIN GROUP(ORDER BY features.feature_name) features, 
        home_type.type_name
    FROM homes
    INNER JOIN home_feature 
      ON homes.home_id = home_feature.home_id
    INNER JOIN home_type 
      ON home_type.type_code = homes.type_code
    INNER JOIN features 
      ON home_feature.feature_id = features.feature_id
    WHERE NOT EXISTS (SELECT home_id
                      FROM bookings b
                      WHERE b.home_id = homes.home_id
                        AND (b.booking_end < to_date('23-Jan-13')
                          OR b.booking_start > to_date('22-Jan-13'))
    GROUP BY homes.home_id, homes.title, 
        homes.description, homes.living_room_count, 
        homes.bedroom_count, homes.bathroom_count, 
        homes.price, homes.sqft, home_type.type_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me with the proper syntax for a case statement using SQL
I wonder if anyone can help improve my understanding of JOINs in SQL. [If
I'm new to querying XML datatype in SQL Server 2005. Anyone can help me
I had problem while executing this SQL statement in MySQL workbench. Can anyone point
Can anyone help with a SQL problem Im having whereby I need to merge
can anyone help, we have a sql server 2005 database installed (actually its an
Can anyone help - this is driving me mad. I am calling a mysql
Can Anyone help me why x2 prints zero. I guess because of floating point
Can anyone help me how to split /explode verse format to 3 parts? The
Can anyone help me to get good WordPress interview questions and answers. Any link

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.