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

  • Home
  • SEARCH
  • 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 6925043
In Process

The Archive Base Latest Questions

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

In MS SQL Server, using the following data, how do I find empIds that

  • 0

In MS SQL Server, using the following data, how do I find empIds that have dept 10 complete (=1) and no entry for dept 11?

deptId    empId   complete
10         3         1
11         3         0
10         4         1
10         5         1
11         5         0
12         5         1
10         6         1
10         7         1
11         7         0

This should return empIds 4 and 6.

  • 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-27T10:44:21+00:00Added an answer on May 27, 2026 at 10:44 am

    Response:

    select distinct empId
    from employees e
    where e.deptId= 10 and complete = 1
    and e.emId not in
      (select s_e.empId
       from employees s_e 
       where s_e.deptId = 11
       )
    

    the query is the list of employees that have dept 10 complete (=1)

    the subquery is the list of employees that has entry for dept11.

    With CTE:

    WITH employees_excluded_CTE (idEmp)
    AS
    (
       select s_e.empId
           from employees s_e 
           where s_e.deptId = 11
    )
     select distinct empId
        from employees e
        where e.deptId= 10 and complete = 1
        and e.emId not in
          (select s_e.empId
           from employees_excluded_CTE
           );
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have always thought that in order to connect to SQL server using windows
I'm using sql server 2008 and have started to find using Indexed Views are
i have the following table data in ms sql server table name category and
I'm trying to drop a SQL Server database using the following code: SqlCommand command
For instance, my query is like the following using SQL Server 2005: SELECT *
I am using SQL Server 2008 management studio to execute the following SQL statements,
I have a install script that uses DATE. I'm running SQL Server 2008 R2,
I've been using SQL Server to store historical time series data for a couple
I have a rather simple web-service which exposes data from sql server. It will
I have quite simple problem in SQL Server: User can have 12 items that

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.