CS FundamentalsHardAmazon/Flipkart SQL round · GATE CS

Table P(x) rows: (1), (2), (2), (3), (NULL). Table Q(x) rows: (2), (3), (3), (NULL), (4). What does this query return?

Table P(x) rows: (1), (2), (2), (3), (NULL). Table Q(x) rows: (2), (3), (3), (NULL), (4). What does this query return?
SELECT COUNT(*) FROM P
WHERE x NOT IN (SELECT x FROM Q);
  1. A. 0
  2. B. 2
  3. C. 3
  4. D. 1

Correct answer: A. 0

Q contains a NULL, so for every P value x NOT IN Q is either FALSE (x found) or UNKNOWN (x compared with NULL). No row is TRUE, so the count is 0.

More DBMS and SQL questions

Exams that ask this topic