Professional Documents
Culture Documents
b) List the names of the employees who are getting the highest salary department
wise.
```sql
SELECT e.ename, e.deptno
FROM employee e
INNER JOIN (
SELECT deptno, MAX(salary) as max_salary
FROM employee
GROUP BY deptno
) emp ON e.deptno = emp.deptno AND e.salary = emp.max_salary;
```
c) List the names of departments where at least 3 are working in that department.
```sql
SELECT d.dname
FROM department d
INNER JOIN (
SELECT deptno
FROM employee
GROUP BY deptno
HAVING COUNT(eno) >= 3
) e ON d.deptno = e.deptno;
```
d) List the employees who are working as Managers using co-related sub-query.
```sql
SELECT e.ename
FROM employee e
WHERE EXISTS (
SELECT 1
FROM employee
WHERE mgrid = e.eno
);
```