Reputation: 9219
There are two tables: employee and department. Employee table has columns: empid, deptid, employeename Departmen table has: deptid, deptname
I want to create a select statment which will list all employees who are part of department having more than 3 employees.
How do I do that?
Upvotes: 0
Views: 54
Reputation: 2467
Just another approach...
Select e.empid, e.employeename
from employee e
where 3 <= (select count(e2.empid)
from employee e2
where e2.empid <> e.empid and e2.deptid = e.deptid)
Upvotes: 1
Reputation: 29214
select empid, employeename
from Employee
where deptid in (
select deptid
from Employee
group by deptid
having count(*) > 3
)
Upvotes: 3