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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:51:35+00:00 2026-06-15T17:51:35+00:00

I’ve 4 tables as shown below doctors id name ———— 1 Mathew 2 Praveen

  • 0

I’ve 4 tables as shown below

doctors

id   name
------------
1   Mathew
2   Praveen
3   Rosie
4   Arjun
5   Denis

doctors_appointments

id  doctors_id    patient_name    contact          date               status
--------------------------------------------------------------------------------------
1   5             Nidhin        9876543210  2012-12-10 15:39:41     Registered
2   5             Sunny         9876543210  2012-12-18 15:39:48     Registered
3   5             Mani          9876543210  2012-12-12 15:39:57     Registered
4   2             John          9876543210  2012-12-24 15:40:09     Registered
5   4             Raj           9876543210  2012-12-05 15:41:57     Registered
6   3             Samuel        9876543210  2012-12-14 15:41:33     Registered
7   2             Louis         9876543210  2012-12-24 15:40:23     Registered
8   1             Federick      9876543210  2012-12-28 15:41:05     Registered
9   2             Sam           9876543210  2012-12-12 15:40:38     Registered
10  4             Sita          9876543210  2012-12-12 15:41:00     Registered

doctors_dutyplan

id   doctor_id    weeks             time           no_of_patients
------------------------------------------------------------------
1       1         3,6,7         9:00am-1:00pm          10
2       2         3,4,5         1:00pm-4:00pm          7
3       3         3,6,7         10:00am-2:00pm         10
4       4         3,4,5,6       8:30am-12:30pm         12
5       5         3,4,5,6,7     9:00am-4:00pm          30

emp_leave

id    empid        leavedate
--------------------------------
1   2   2012-12-05 14:42:36
2   2   2012-12-03 14:42:59
3   3   2012-12-03 14:43:06
4   3   2012-12-06 14:43:14
5   5   2012-12-04 14:43:24

My task is to find all the days in a month in which the doctor is available excluding the leave dates.

My query what is wrote is given below:

SELECT DATE_ADD( '2012-12-01', INTERVAL
ROW DAY ) AS Date,
ROW +1 AS DayOfMonth
FROM (

SELECT @row := @row +1 AS
ROW FROM (

SELECT 0
UNION ALL SELECT 1
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
)t1, (

SELECT 0
UNION ALL SELECT 1
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
)t2, (

SELECT @row := -1
)t3
LIMIT 31
)b
WHERE DATE_ADD( '2012-12-01', INTERVAL
ROW DAY )
BETWEEN '2012-12-01'
AND '2012-12-31'
AND DAYOFWEEK( DATE_ADD( '2012-12-01', INTERVAL
ROW DAY ) ) =2
AND DATE_ADD( '2012-12-01', INTERVAL
ROW DAY ) NOT
IN (

SELECT DATE_FORMAT( l.leavedate, '%Y-%m-%d' ) AS date
FROM doctors_dutyplan d
LEFT JOIN emp_leave AS l ON d.doctor_id = l.empid
WHERE doctor_id =2
)

This works fine for all doctors who took any leave in a particular day in a month (here in the example it is Decemeber 2012). and the result for the above query is shown below:

Date         DayOfMonth
-----------------------
2012-12-10       10
2012-12-17       17
2012-12-24       24
2012-12-31       31

But on the other hand for the doctors who didn’t took any leave , for that my query is showing empty table, example for the doctor Mathew whose id is 1, my query returns an empty result

can anyone please tell a solution for this problem.

Thanks in advance.

  • 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-15T17:51:37+00:00Added an answer on June 15, 2026 at 5:51 pm

    Your query is large, but this part looks fishy:

    NOT IN (
        SELECT DATE_FORMAT( l.leavedate, '%Y-%m-%d' ) AS date
        FROM doctors_dutyplan d
        LEFT JOIN emp_leave AS l ON d.doctor_id = l.empid
        WHERE doctor_id =2
    

    The left join means a null would be returned for doctor 1. Now, col1 not in (null) does not behave as you may expect. It translates to:

    col1 <> null
    

    Which is never true. You could solve this by changing the left join to an inner join, so an empty set instead of null is returned for a doctor without leave.

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

Sidebar

Related Questions

I have two tables with like below codes: Table: Accounts id | username |
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
string formIdList = 8256, 8258, 8362, 8120, 8270, 8271, 8272, 8273, 8257, 8279, 8212,
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.