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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:50:08+00:00 2026-06-05T10:50:08+00:00

I have three tables Employee SSN Name 1 a 2 b 3 c Projects

  • 0

I have three tables

    Employee    
    SSN Name
    1   a
    2   b
    3   c

    Projects    
    Pno Name
    1   x
    2   y
    3   z

    Works_On    
    ESSN    Pno
    1       1
    1       2
    2       1
    3       1
    3       2
    3       3

Okay so the question is, how do I know (by query) which employee works on ALL projects. I cant seem to compare multi with multi.

Thank you and sorry for a silly question.

  • 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-05T10:50:09+00:00Added an answer on June 5, 2026 at 10:50 am

    One way to do it is to count all projects, count number of projects for employee and then select all employees that work on the same number of projects:

    DECLARE @ProjectCount int
    SELECT @ProjectCount = Count(*) FROM Projects
    
    SELECT e.* 
    FROM Employee e
    WHERE (SELECT COUNT(1) FROM Works_On w WHERE w.ESSN = e.SSN) = @ProjectCount
    

    ProjectCount variable is there to skip counting projects for every employee.

    UPDATE: How it works:

    For each employee count how many records are in Works_On table with field ESSN equal to current employee’s SSN and then compare that number to total number of projects.
    Query:

    SELECT COUNT(1) FROM Works_On
    

    will give you total number of records in Works_On table (6 in your case). We want to count how many records are there for each employee and that’s why we embedded that query in our main query with condition to select only records from Works_On table that have current employee’s SSN. If you had to write this in some programming language, this would be logically equivalent to foreach loop on employees collection where in body of the loop you select all records from Works_On table for current employee and then compare it with total number of projects. If current employee has number of projects equal to the total number of projects, count it.

    I hope this helps.

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

Sidebar

Related Questions

I have three tables: Employee(Id,name etc) Appointment(Id,date,time,employee id, clientid etc) Client(Id,name etc) The Employee
I have three tables A: A.pID primary key, A.Name nvarchar(250) B: B.pID primary key,
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have three tables: Employee , Emp_Address and Emp_AddressDetail . Employee table is master
I have three tables in my database. First table is Employee : Second table
I have three tables A, B, C. A having Id,Name,Address coulmns. B is the
I currently have quite a messy query, which joins data from multiple tables involving
I have 4 tables Table1 (employee) id name -------------------- 1 a 2 b Table2
I have three tables: User, Employee and Worker. User table has one-to-zero-or-one relationship with
I have two tables Employee (EmpID, Name, UpdatedBy, UpdateDate) EmpContact (ContactID, Contact,EmpID) I am

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.