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
- 4
- 3
- 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 ▸