I want to use subqueries in SQL in Oracle Express for getting the salary_id of the highest salaries that the employees get in their departments. The tables that I have are:
Employee
Emp_id Salary Dept_id
100 1000 a101
200 2000 a101
300 2500 b102
Salary
Grade LowSal HiSal
1 500 900
2 901 2000
3 2001 3000
First I extracted the maximum salary in each department with this query:
SELECT Max(e.SALARY)
FROM EMPLOYEE e
GROUP BY e.DEPT_ID
The results are two records: 2000 and 2500
The next step is to get the grades of those salaries, so I use the following:
SELECT GRADE
FROM SALARY
WHERE (SELECT Max(e.SALARY)
FROM EMPLOYEE e
GROUP BY e.DEPT_ID) BETWEEN LOWSAL AND HIGHSAL;
The error that I received is: ORA-01427: single-row sub-query returns more than one row
How I can do that SQL command with sub-queries in SQL?