$ ./guess_the_languageSQL & Databases
SQL & Databases · hard · #40

What does the final query return?

-- SQLite / PostgreSQL
CREATE TABLE u (email TEXT UNIQUE);
INSERT INTO u VALUES (NULL);
INSERT INTO u VALUES (NULL);
SELECT COUNT(*) FROM u;
  1. Error on insert
  2. 2
  3. 0
  4. 1
NULLs are not equal to each other, so a standard UNIQUE constraint accepts any number of them.
Play SQL & Databases ▸