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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:53:14+00:00 2026-05-27T16:53:14+00:00

I am new to this after spending 2 days trying to find an answer

  • 0



I am new to this after spending 2 days trying to find an answer on the net
I am trying to construct a MYSQL select statement

I have 2 tables on ethat contains a list of dates and prices, the second is a table of reservation dates with start and end. I am tring to show al the FREE dates & prices in Table 1 that DO NOT exist in any of the reservation records in Table 2

Table 1 called – dates_prices –
id, date, price

example data

333, 2011-12-20, 66.00
333, 2011-12-21, 66.00
333, 2011-12-22, 66.00
333, 2011-12-23, 66.00
333, 2011-12-24, 66.00
333, 2011-12-25, 66.00
333, 2011-12-26, 66.00
333, 2011-12-27, 66.00
333, 2011-12-28, 66.00
333, 2011-12-29, 66.00
333, 2011-12-30, 66.00

Table 2 – reservations

id, startdate, enddate

example data

333, 2011-12-20, 2011-12-22
333, 2011-12-24, 2011-12-26
333, 2011-12-28, 2011-12-30

I need to extract ONLY the dates from Table 1 that do not exist in the Table 2 records between start and end dates of all records in table 2 with the same ID number 333

So the only records that should be displayed from table 1 are as follows

id, date, price

333, 2011-12-23, 66.00
333, 2011-12-27, 66.00
333, 2011-12-31, 66.00
  • 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-27T16:53:15+00:00Added an answer on May 27, 2026 at 4:53 pm
    create table  table12 (id int, datefor date, price int)
    
    insert  into  table12
    select 333, '2011-12-20', 66.00
    union all
    select 333, '2011-12-21', 66.00
    union all
     select 333, '2011-12-22', 66.00
     union all
     select 333, '2011-12-23', 66.00
     union all
    select 333, '2011-12-24', 66.00
    union all
     select 333, '2011-12-25', 66.00
     union all
     select 333, '2011-12-26', 66.00
     union all
     select 333, '2011-12-27', 66.00
     union all
     select 333, '2011-12-28', 66.00
     union all
     select 333, '2011-12-29', 66.00
     union all
     select 333, '2011-12-30', 66.00 
    
     create table  table2 (id int, startdate date, enddate date)
    
    insert  into  table2
    select 333, '2011-12-20', '2011-12-22'
     union all
     select 333, '2011-12-24', '2011-12-26'
     union all
     select 333, '2011-12-28', '2011-12-30'
    

    try this after creating above tables. solution to ur probelm is u need to make this type of query to tables ie
    select * from table12 where datefor not between ‘2011-12-20’ and ‘2011-12-22’ and datefor not between ‘2011-12-24’ and ‘2011-12-26’ and datefor not between ‘2011-12-28’ and ‘2011-12-30’ and table12.id=333 i have made one proc just u need to pass ur id.

    create proc solution( @id int) 
      as
      begin
    
    declare @count int
        declare @i int
        declare @query varchar(800)
        set @query=''
     declare @startdate varchar(80)
        set @startdate=''
         declare @enddate varchar(80)
        set @enddate=''
    
     declare @table table( row int ,startdate date,enddate date,id int)
    insert into @table select row_number() over(order by (select 1)) as rownumber  ,startdate,enddate,id  from  table2  where table2.id=@id
     set  @count=(select COUNT (*)  from  @table )
     set   @i=1
     set @query += 'select * from  table12 where '
    while @count>=@i
    begin
     set @startdate=( select startdate  from  @table  where row=@i) 
     set  @enddate =(select enddate  from  @table  where row=@i)
     set @query +=  ' datefor not between '+''''+@startdate+''''+ ' and '+'''' +@enddate+''''
     if   @count>@i
     begin
     set @query +=' and  '
     end
     if @count=@i
     begin
     set @query += ' and  table12.id='+cast (@id as varchar(50)) +''
     end 
    
    set @i+=1
     end
     if(@i=1)
     set @query+='table12.id='+cast (@id as varchar(50)) +''
    
    
      exec (@query)
    end
    
    exec solution 333
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After spending a good 3 to 4 hours on google trying to find any
After spending half an hour to find a proper, self-explaining title for this question,
after spending 2 solid days searching for an answer, I would like to ask
I'm new to java and android development. After spending few days working with java
After creating a new form, I usually perform this ritual: Change the name into
I'm finding this kind of overriding after a new in java code very often
I am new this sharepoint development and i have task in hand to do
New to this library (no more familiar with BeautifulSoup either, sadly), trying to do
Im new to this.I have a cron file called xml.php and i want to
I am new to this technology. I searched a lot but cant find any

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.