Knowee
Questions
Features
Study Tools

Mr. John is the president of a company. Five managers report to him. All other employees report to these managers.Examine the code:SELECT employee.ename FROM emp employeeWHERE employee.empno NOT IN (SELECT manager.mgrFROM emp manager);The above statement returns no rows selected. as the result. Why?Select one:a.A NULL value is returned from the subquery.b.NOT IN operator is not allowed in subqueries.c.None of the employees has a manager.d.All employees have a manager.

Question

Mr. John is the president of a company. Five managers report to him. All other employees report to these managers.Examine the code:SELECT employee.ename FROM emp employeeWHERE employee.empno NOT IN (SELECT manager.mgrFROM emp manager);The above statement returns no rows selected. as the result. Why?Select one:a.A NULL value is returned from the subquery.b.NOT IN operator is not allowed in subqueries.c.None of the employees has a manager.d.All employees have a manager.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The answer is a. A NULL value is returned from the subquery.

The reason is that the NOT IN operator in SQL does not return any rows when the subquery results in any NULL values. This is because NOT IN treats NULL as an unknown value, and any comparison with an unknown value also results in an unknown, which is not included in the final result set.

So, if the subquery (SELECT manager.mgr FROM emp manager) returns any NULL values, the whole main query (SELECT employee.ename FROM emp employee WHERE employee.empno NOT IN...) will return an empty set, which is why you get "no rows selected."

To avoid this, you can use NOT EXISTS or exclude NULL values from the subquery.

This problem has been solved

Similar Questions

Evaluate this SQL statement:SELECT first_name, commissionFROM employeeWHERE commission =(SELECT commissionFROM employeeWHERE UPPER(first_name) = 'SCOTT');What would cause this statement to fail?Select one:a.All the given optionsb.The FIRST_NAME values in the database are in lowercase.c.There is more than one employee with the first name Scott.d.Scott has a zero commission value.e.Scalar function is not allowed in Subquery.

Consider the table EMPLOYEE(empId, name, department, salary) and the two queries Q1 ,Q2 below. Assuming that department D5 has more than one employee, and we want to find the employees who get higher salary than anyone in department D5, which one of the statements is TRUE for any arbitrary employee table?Q1 :  SELECT  e.empId FROM employee e WHERE NOT EXIST (SELECT * From employee s where s.department = “D5” AND  s.salary >=e.salary)Q2 : SELECT  e.empIdFROM employee eWHERE e.salary > Any (Select distinct salary From employee s Where s.department = “D5”)Q1 is the correct queryQ2 is the correct queryBoth Q1 and Q2 produce the same answer.Neither Q1 nor Q2 is the correct query

he following query throws an error. Choose the correct reason for the error as given in the options. SELECT first_name, last_nameFROM employeesWHERE commission_pct = (SELECT min(commission_pct ) FROM employees GROUP BY department_id); A. The GROUP BY clause is not required in the sub-queryB. A function cannot be used in a sub-query SELECT statementC. The single row sub-query gives multiple records

You encounter the following statements:SELECT e1.ename|| 'works for '||e2.ename "Employees and their Managers" FROM emp e1, emp e2 WHERE e1.mgr=e2.empno;  What kind of join is this?

Evaluate below sql statement SELECT emp_name, department FROM employees WHERE department = 'HR' UNION SELECT contractor_name, department FROM contractors WHERE department = 'IT';Select one:a. Retrieves the names of all employees and contractors from the HR and IT departments.b. Retrieves the names of employees from the HR department and all contractors.c. Retrieves the names of employees and contractors from the HR and IT departments, excluding employees from the IT department and contractors from the HR department.d. Retrieves the names of employees from the HR department and contractors from the IT department.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.