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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:43:57+00:00 2026-05-23T10:43:57+00:00

Here is a simplified schema of my database: Users ———————————— UserID | Name |

  • 0

Here is a simplified schema of my database:

Users
------------------------------------
UserID | Name      | Assignable
------------------------------------
  5    | John Doe  |      1

TimeSlots
-------------------------------------------------------
TimeSlotID | StartTime           | EndTime
-------------------------------------------------------
     3     | 2011-06-30 15:00:00 | 2011-06-30 16:00:00

Appointments
------------------------------------
TimeSlotID | UserID
------------------------------------
     3     |    5   

I have Users that can be assigned to TimeSlots that make up Appointments. I need a way to start with a start and end time and query all Users that are able to be assigned (Assignable flag set to 1) and have no time conflicts (Appointments that overlap) with those times.

Older TimeSlots will be in there too so you would only be interested in TimeSlots that are now or in the future.

  • 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-23T10:43:58+00:00Added an answer on May 23, 2026 at 10:43 am
    select *
    from users u    
    where u.Assignable = 1
        and u.UserID not in (
           select UserID
           from Appointments a
             join TimeSlots t on a.TimeSlotID = t.TimeSlotID 
           where t.EndTime > now()
              and t.EndTime > @desiredStartTime
              and t.StartTime < @desiredEndTime
        )
    

    edit Taking a cue from tandu

    I think this would also work, and it has the added performance benefit of no subqueries:

    select *
    from users u    
        left join Appointments a on a.UserID = u.UserID
        left join TimeSlots t on (
        a.TimeSlotID = t.TimeSlotID 
           and t.EndTime > now()
           and t.EndTime > @desiredStartTime
           and t.StartTime < @desiredEndTime
        )
    where 
        u.Assignable = 1
        and t.TimeSlotID is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just getting into SQL stored queries right now... anyway, here's my database schema (simplified
I've got 3 tables that are something like this (simplified here ofc): users user_id
I want to list all users with their corropsonding user class. Here are simplified
Here is a simplified version of my database model. I have two tables: Image,
I've hit a bit of a wall ... here is my simplified schema: TABLE
I have a database where I store objects. I have the following (simplified) schema
Here is simplified version of my requirement I have a java class say Processor
Here's a simplified version of what I'm trying to do : Before any other
Here is a simplified version of my application showing what I'm doing. /* in
Here's a simplified version of my class: public abstract class Task { private static

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.