• retagged by
1,650 views
6 6 votes

Consider the following table Mystery

Mystery
A B
1 Null
2 4
3 5
Null 6

select count(\ast) from Mystery
where A not in( select B from Mystery)

(A) 1

(B) 0

(C) 4

(D) 3

ans is B given

please explain how??

1 Answer

6 6 votes

This will give 0...because of null values...where will work like if it is true for that value then the row is returned or false it will not return the row with that value....on the otherhand null is a unknown value so when it is compared with true,false or unknown it return unknown itself so when there are null the not in operator cannot give the correct truth or false values...

 

on the other hand "in" will work perfectly fine

the query can be simplified like this 

select count(\ast) from Mystery 
where A not in( select B from Mystery)

this will evaluate as

select count(\ast) from Mystery 
where (1<>NUll and 1<>4 and 1<>5 and 1<>6) or (2<>NULL and 2<>4......)or (3<>Null.....) or (NULL<>NULL....)

so 1<>NUll--unknown and 1<>4--true and 1<>5--true and 1<>6--true

eventhough rest of them are true due to "and" of unknown the expression evaluates to unknown...

where will return particular row only when it is evaluated to true

• edited by
Position:
Show:

Related questions

4 4 votes
3 3 answers
2.9k
2.9k views
indrajeet asked Sep 22, 2016
2,876 views
Let R(a,b) be a schema and Q1 and Q2 are queries on R.Q1: SELECT * FROM R;Q2: (SELECT * FROM R) INTERSECT (SELECT * FROM R);Which of the following statements is true?(A) ...
0 0 votes
0 0 answers
1.0k
1.0k views
Beyonder asked Nov 30, 2016
1,046 views
Can Anyone Explain how Query 28 works with example.
0 0 votes
1 1 answer
1.8k
1.8k views
aditya kuppa 1 asked Dec 5, 2017
1,824 views
How many minimum tables are required for this er diagram consisting of a many - many relation and total participation of one of the entities.? Can't i merge relation R an...
2 2 votes
2 2 answers
4.5k
4.5k views
indrajeet asked Sep 23, 2016
4,545 views
Consider the following entity relation diagramIf A has 50 entities,B has 20 entities and C has 200 entities. what is the maximum number of triples of entities that could ...