You are on page 1of 1

Question 6 from DBMS PREVIOUS YR PAPER

a) List the employee name, job who are without manager.


```sql
SELECT ename, job
FROM employee
WHERE mgrid IS NULL;
```

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
);
```

e) List the Department number where there are no employees.


```sql
SELECT d.deptno
FROM department d
LEFT JOIN employee e ON d.deptno = e.deptno
WHERE e.eno IS NULL;
```
Please replace the table and column names if they are different in your database.
Also, make sure to run these queries in a transaction-safe environment to avoid any
unintended side effects. Let me know if you need help with anything else. 😊

You might also like