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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:27:37+00:00 2026-05-21T22:27:37+00:00

I have a table that that I am trying to query against itself and

  • 0

I have a table that that I am trying to query against itself and I’m not sure how to go about it.

Table name: schedule

  • user_id
  • startdate
  • enddate
  • sequencyID

The situation is I have a number of rows where the user_id = 0. This represents an open schedule that someone can claim. If a schedule gets claimed it gets assigned a specific user id. Here is where the tricky part comes in. I am trying to pick a user and display schedule times that don’t overlap with what they have already been accepted or been scheduled.

Here is what I have so far

SELECT * 
  FROM schedule 
 WHERE user_id = 123456;

That gets me all the ranges of times a person has already accepted

SELECT * 
  FROM schedule 
 WHERE user_id = 0;

This gets me all the schedule rows that are available. I’m not quite sure how to combine them such that the final result is a list of schedule elements whos user_id =0 and the startdate / enddate don’t exist between the startdate and endate from the ones already assigned a user.

I would think it would be something like

SELECT * 
  FROM schedule 
 WHERE user_id = 0 
   AND (loop through schedule rows testing for 
           (startdate < loopstartdate and enddate < loopstartdate) || 
           (startdate > loopenddate)

The where is what I’m struggling with. Any ideas? If someone could at least point me in the right direction to what mechanism I’d use to begin to solve this type of problem that would be awesome.

  • 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-21T22:27:37+00:00Added an answer on May 21, 2026 at 10:27 pm
    SELECT a.*
    FROM schedule a
    WHERE user_id = 0
      AND NOT EXISTS (
        SELECT NULL
          FROM schedule b
          WHERE b.user_id = 123456
            AND b.start_date <= a.end_date
            AND b.end_date >= a.start_date
      )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query against two databases that I'm trying to execute. The first
I have a table that has redundant data and I'm trying to identify all
I'm trying to normalize a mysql database.... I currently have a table that contains
I have a heap based table in MySQL that I am trying to update
I'm trying to have a simple html table, that highlights a row as a
I have table that I insert data with following query (from c# code): INSERT
I'm trying to run a query in SQL Server 2008 against a table where
I am trying to do a query against the database where I have contacts
I am trying to query a database. I already have a file that includes
I have a 3 tables that I'm trying to join and get distinct results.

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.