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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:26:02+00:00 2026-06-10T23:26:02+00:00

I have two mysql tables, schedule and appointment. In schedule table there is defined

  • 0

I have two mysql tables, schedule and appointment. In schedule table there is defined doctor termins and in other there are booked appointments. The problem is that the doctor can always change his termins and I can’t paste reference in appointments table and I only want to get available termins in one mysql query for both doctors. Is that posible?

CREATE TABLE `schedule` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `from` timestamp NULL DEFAULT NULL,
  `to` timestamp NULL DEFAULT NULL,
  `doctor_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;


INSERT INTO `schedule` (`id`, `from`, `to`, `doctor_id`)
VALUES
    (1, '2012-09-06 14:00:00', '2012-09-06 14:59:59', 1),
    (2, '2012-09-06 15:00:00', '2012-09-06 15:59:59', 1),
    (3, '2012-09-06 16:00:00', '2012-09-06 16:59:59', 1),
    (4, '2012-09-06 17:00:00', '2012-09-06 17:59:59', 1),
    (5, '2012-09-06 14:00:00', '2012-09-06 14:59:59', 2),
    (6, '2012-09-06 15:00:00', '2012-09-06 15:59:59', 2),
    (7, '2012-09-06 16:00:00', '2012-09-06 16:59:59', 2),
    (8, '2012-09-06 17:00:00', '2012-09-06 17:59:59', 2);

CREATE TABLE `appointments` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `from` timestamp NULL DEFAULT NULL,
  `to` timestamp NULL DEFAULT NULL,
  `doctor_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;


INSERT INTO `appointments` (`id`, `from`, `to`, `doctor_id`)
VALUES
    (3, '2012-09-06 16:00:00', '2012-09-06 16:59:59', 1),
    (4, '2012-09-06 17:00:00', '2012-09-06 17:59:59', 1),
    (5, '2012-09-06 14:00:00', '2012-09-06 14:59:59', 2),
    (8, '2012-09-06 17:00:00', '2012-09-06 17:59:59', 2);
  • 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-10T23:26:04+00:00Added an answer on June 10, 2026 at 11:26 pm

    If it is guaranteed that appointments id will equal schedule id then:

    select `id`,`from`,`to`,`doctor_id`
    from schedule
    where `id` not in 
    (select `id` from appointments)
    order by `doctor_id`,`from` 
    

    Sqlfiddle

    If appointments id is not guaranteed to be linked then:

    select `id`,`from`,`to`,`doctor_id`
    from schedule
    where `id` not in 
    (select `t1`.`id` 
    from(
    select `s`.`id`,`s`.`from`,`s`.`to`,`s`.`doctor_id` 
    from schedule as s 
    inner join 
    appointments as a
    on `s`.`doctor_id`=`a`.`doctor_id`
    and `s`.`from`=`a`.`from`
    and `s`.`to`=`a`.`to`)
    as t1)
    

    Sqlfiddle

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

Sidebar

Related Questions

I have two MySQL tables, j and t, with a third normalising table, jt.
I have two MySQL tables a and b with fields x and y. Table
I have the following two mySQL tables with the 'child' table having a DELETE
I have two mySQL tables as follows: [product] table P_id | Name | Quantity
I have two MySql tables as shown below with the data shown: CREATE TABLE
Ok, I have two MYSQL tables: CREATE TABLE `sessions` ( `id` int(11) NOT NULL
I have two MySQL tables A and B . Table A has a member
I have two MySQL tables and I would like to know if there is
I have two mysql tables - a sales table: +----------------+------------------------------+------+-----+---------+-------+ | Field | Type
I have two mysql tables, one listing article names, the other listing the authors

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.