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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:59:06+00:00 2026-06-17T07:59:06+00:00

I have a mysql query that returns time slots. I have a table called

  • 0

I have a mysql query that returns time slots. I have a table called timeslots that contains starttimeb, endtimeb and employeeb. Booked Starttime and endtime fields pull from a different table called schedule. The problem is I can only assign appointments defined by the timeslots table.

For example I would like slots 8:00 to 10:00, 10:00 to 12:00, 12:00 to 14:00, 14:00 to 16:00 and 16:00 to 18:00 not available if there is 1 scheduled item with a starttime of 08:00 and a endtime of 18:00 in the schedule table. Business hours are defined as 8:00 to 18:00 so only two hour time blocks are available during that time and it is possible an appointment may be booked for more than the 2 hour time slots provided in the timeslots table, so for example if 8:00 to 12:00 has been booked I would only want 12:00 to 14:00, 14:00 to 16:00 and 16:00 to 18:00 to be available. Or if 9:00 to 11:00 was booked only 12:00 to 14:00, 14:00 to 16:00 and 16:00 to 18:00 would be available.

mysql_query( "SELECT *
FROM timeslots
LEFT OUTER JOIN
 (SELECT 
   starttime
 , endtime
 , custno
 , id
FROM schedule
WHERE schedule.date = '2012-12-14'
 ) AS a
 ON a.starttime >= timeslots.starttimeb
 AND a.endtime <= timeslots.endtimeb
 AND a.custno = timeslots.custnob" );

The query above returns something like this… On my app it is set that if starttime is null timeslot is available.

starttimeb endtimeb custnob            starttime endtime  custno          id
08:00:00   10:00:00 Michael W Sloan    08:00:00  10:00:00 Michael W Sloan 15670
10:00:00   12:00:00 Michael W Sloan    NULL      NULL     NULL            NULL
12:00:00   14:00:00 Michael W Sloan    NULL      NULL     NULL            NULL 
14:00:00   16:00:00 Michael W Sloan    14:00:00  16:00:00 Michael W Sloan 15673
16:00:00   18:00:00 Michael W Sloan    NULL      NULL     NULL            NULL
08:00:00   10:00:00 James T Reesor     08:00:00  10:00:00 James T Reesor 15664
10:00:00   12:00:00 James T Reesor     NULL      NULL     NULL            NULL
12:00:00   14:00:00 James T Reesor     NULL      NULL     NULL            NULL
14:00:00   16:00:00 James T Reesor     NULL      NULL     NULL            NULL
16:00:00   18:00:00 James T Reesor     16:00:00  18:00:00 James T Reesor 15674
08:00:00   10:00:00 Carlton L. Pierce  NULL      NULL     NULL            NULL
10:00:00   12:00:00 Carlton L. Pierce  NULL      NULL     NULL            NULL
12:00:00   14:00:00 Carlton L. Pierce  12:00:00  14:00:00 Carlton L. Pierce 15671
14:00:00   16:00:00 Carlton L. Pierce  NULL      NULL     NULL            NULL
16:00:00   18:00:00 Carlton L. Pierce  NULL      NULL     NULL            NULL
08:00:00   10:00:00 Frankie D Aldridge NULL      NULL     NULL            NULL
10:00:00   12:00:00 Frankie D Aldridge NULL      NULL     NULL            NULL
12:00:00   14:00:00 Frankie D Aldridge NULL      NULL     NULL            NULL
14:00:00   16:00:00 Frankie D Aldridge NULL      NULL     NULL            NULL
16:00:00   18:00:00 Frankie D Aldridge NULL      NULL     NULL            NULL
08:00:00   12:00:00 Michael W Sloan    08:00:00  10:00:00 Michael W Sloan 15670
  • 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-17T07:59:07+00:00Added an answer on June 17, 2026 at 7:59 am

    It is difficult to understand what the question is, but if the problem is that you want to find if any rows from schedule overlaps with the times in the timeslot table, changing

    ON a.starttime >= timeslots.starttimeb
    AND a.endtime <= timeslots.endtimeb
    

    which only matches schedule rows that both starts and ends within a given timeslot, into

    ON a.starttime < timeslots.endtimeb
    AND a.endtime > timeslot.starttimeb
    

    which matches schedule rows that is neither completely before nor completely after the timeslot in question, might help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP/MySQL query that returns to an HTML table, and I'm stuck
I'm running an MySQL query that returns results based on location. However I have
I have a method that basically returns the results of a mysql query. public
I have a MySQL query that returns a result with a single column of
I have a query in MySQL that returns three columns, a Candidate's ID, the
if i have a mysql query that returns some values, these values are categorized
I have a MySQL query that I would like to optimize a little bit.
I have a mysql query that targets a single column in a single row
I have a MySQL query that: gets data from three tables linked by unique
I have a mysql query that uses union to join multiple queries into one

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.