r/DatabaseHelp • • Oct 16 '17
Oracle hr schema, subquery problem
Hi, I have been tasked with performing the following query: display the last_name, first_name, and department_id of all employees in the department that has the lowest average salary. Here is what I think the query should be: select department_id, last_name, first_name from employees where department_id in(select min(avg(salary)) from employees group by department_id); Please point me in the direction (Oracle documentation or elsewhere) to help me solve this problem. Thank you!
1
Upvotes
View all comments
Show parent comment
1
u/[deleted] Oct 17 '17
Ok. Here is where I am at: inner query is successful in producing the dept id and the minAvgSal but when i wrap the outer query around it I get a "too many values" error. select department_id, avg(salary) from employees group by department_id having avg(salary)= (select min(avg(salary)) from employees group by department_id);---inner query
select last_name, first_name,department_id where department_id=(subquery);--outer q around inner q above, produces error "too many values."
I'm still doing something wrong but I don't understand what or why. If the (only)department id output by the subquery is 50, why can't the outer query simply be equal to the one and only department_id output by the subquery, ie 50?