Skip to content
Advertisement

single-row subquery returns more than one row in oracle in HR schema

select employee_id, first_name, job_id, salary 
from employees where salary < ( select SALARY 
                                FROM EMPLOYEES 
                                WHERE JOB_ID='IT_PROG');

and I found an error like the following :

ORA-01427: single-row subquery returns more than one row

Advertisement

Answer

Looks like there are “many” employees whose job_id = 'IT_PROG'. In that case, subquery returns “many rows” and your query results in an error.

It depends on what you want to do in such a case; for example, you might want to return rows for employees whose salary is lower than minimum salary for IT_PROG, so that would be

SELECT employee_id,
       first_name,
       job_id,
       salary
  FROM employees
 WHERE salary < (SELECT MIN (SALARY)               --> note MIN function here
                   FROM EMPLOYEES
                  WHERE JOB_ID = 'IT_PROG');
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement