CS FundamentalsModerateProduct placement · SQL round

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 JOIN Q ON P.x = Q.x;
  1. A. 4
  2. B. 5
  3. C. 3
  4. D. 2

Correct answer: A. 4

Join pairs: P's two 2s each match Q's single 2 (2 pairs); P's 3 matches Q's two 3s (2 pairs). NULLs never satisfy '=', so 4.

More DBMS and SQL questions

Exams that ask this topic