$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #257

What is the output?

CREATE TABLE t (x INT);
INSERT INTO t VALUES (1), (NULL), (NULL), (1);
SELECT COUNT(*) FROM (SELECT DISTINCT x FROM t);
  1. 1
  2. 4
  3. 3
  4. 2
DISTINCT treats all NULLs as one group, so the subquery returns two rows: 1 and NULL. COUNT(*) counts rows, NULL included.
Play Problem Solving ▸