Skip to content
Advertisement

Select query in SQL SERVER need to support

I have 3 tables like that:

- Employee_Table (Employee_Number, Employee_Name, Department_Number) 
    With Employee_Number is PRIMARY KEY, Department_Number is FOREIGN KEY;

- Employee_Skill_Table (Employee_Number, Skill_Code, Date Registered) 
    With PRIMARY KEY (Employee_Number, Skill_Code);

- Department (Department_Number, Department_Name) 
    With PRIMARY KEY (Department_Number); 

How can I specify

the departments which have >= 3 employees

Help me!

Advertisement

Answer

If you only need the departments that have more than 3 people try this query

SELECT d.Department_Name
FROM Department d 
JOIN Employee_Table e ON e.Department_Number = d.Department_Number
GROUP BY Department_Name
HAVING COUNT(*) >= 3
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement