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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:34:02+00:00 2026-06-02T13:34:02+00:00

I am storing employee attendance on a table ‘attendance’ having the following structure: EmpID,

  • 0

I am storing employee attendance on a table ‘attendance’ having the following structure:

EmpID, CDate

Attendance system insert this table everyday with employee-id of all employees present on that particular day.

I need to find out absent statement of a particular employee. I can do this easily by selecting all distinct date that are not in – dates where the employee is present.

Is there any way I can remove the not in operator on that sql statement. Please help

Here is the sql query for employee with EmpId 01:

select distinct CDate 
  from attendance 
  where CDate not in (
      Select CDate from attendance where EmpID='01') 
  • 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-02T13:34:03+00:00Added an answer on June 2, 2026 at 1:34 pm

    The problem isn’t in the NOT IN clause, it is the subquery.

    You want something more like:

    SELECT DISTINCT a1.CDate, if (EmpID=NULL, false,true) as Present
    FROM attendance as a1
    LEFT JOIN attendance as a2 USING (CDate) 
    WHERE a2.EmpID='01'
    

    This is a cartesian join which pulls all of the dates, then joins the employee attendance status on that. Should be significantly faster than your subquery.


    Updated, with tested code:

    SELECT DISTINCT a1.CDate, IF (a2.EmpID IS NULL, false,true) as Present
    FROM attendance AS a1
    LEFT JOIN attendance AS a2 ON (a1.CDate = a2.CDate AND a2.EmpID='01') 
    

    My bad on the previous answer. I should have put the subselection into the ON instead of an aggregate.

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

Sidebar

Related Questions

Consider the following inheritance: abstract class Employee { private string empID; private string empName;
I have a table where I am storing employee details. I want to alter
As I am working on Employee Management system, I have two table (for example)
I am using the TIME data type for storing the employee extra hours worked,
I am doing a project which is based on storing the employee details, like
I have the following code: class Employee { friend string FindAddr( list<Employee> lst,string name
For C# properties, I can do this: public class Employee{ public string Name {
I have a List<Employee> . Each Employee has a byte[] storing a picture (or
I am storing two XML documents, namely hospital and office, in BaseX. The following
I have a employee table with columns like emp_id, firstname, lastname, month and year.

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.