retagged by
429 views
3 votes
3 votes

What is the number of rows returned by an SQL query on the below EMP table?

$\begin{array}{|c|c|c|} \hline \text{eno} & \text{ename} & \text{manager} \\ \hline 1 & A & \text{Null} \\ \hline 2 & B & \text{Null} \\ \hline 3 & C & \text{Null} \\ \hline 4 & D & \text{Null} \\ \hline \end{array}$

SELECT * FROM EMP where manager IN (NULL, NULL,NULL);
  1. It will throw an error.
  2. Three rows are selected.
  3. No rows are selected.
  4. One row is selected.
retagged by

1 Answer

Best answer
5 votes
5 votes

NULL should not be used in NOT IN or IN statements.

Result of an evaluation with NULL is always NULL.

An IN statement will be parsed identically to field=val1 or field=val2 or field=val3.

So putting a null in there will result in field=null......which won't work.

This is why no rows will be returned.

Please refer to the following link for further details.

https://web.archive.org/web/20141229070855/http://www.oraclebin.com/2013/01/beware-of-nulls.html

I found the answer in the following link:

https://stackoverflow.com/questions/6362112/in-clause-with-null-or-is-null/39452788#39452788

selected by
Answer:

Related questions

577
views
2 answers
0 votes
Bikram asked Aug 26, 2017
577 views
Consider the following set of relations: EMP (eno, ename , dno) DEPT (dno, dname)Primary key columns are underlined and dno in EMP is a foreign key referrin...
513
views
0 answers
3 votes
Bikram asked Aug 26, 2017
513 views
Consider the relation:Exam(eid, marks)Assume that marks take not null integers only. Also, marks takes distinct values and the number of tuples are odd.Select marks from ...
574
views
1 answers
7 votes
Bikram asked Aug 26, 2017
574 views
Consider the table ‘employee’ having two columns: 'EmpNo' and 'EmpName'.Run the following transaction on the table:COMMIT; ALTER TABLE employee ADD PhoneNo varchar(10...
442
views
1 answers
2 votes
Bikram asked Aug 26, 2017
442 views
Consider the following relation schema:Student (RollNo, Sname, Scity) Packages (Pcode, Pname, Price) Registers (RollNo PCode, Date) What does the following SQL quer...