SQL-Quiz: COUNT(*) vs COUNT(column)

COUNT(*), COUNT(column) and COUNT(DISTINCT column) look alike but count different things. This SQL quiz tests how each one treats NULL, empty strings and duplicates, with a classic trap or two.

Mittel 10 Fragen ~6 Minuten Bestanden ab 80% SQLite

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 10

What does this query return?

CREATE TABLE customers (name TEXT, email TEXT, phone TEXT);
INSERT INTO customers VALUES ('Ana', 'a@x.com', NULL), ('Ben', NULL, NULL), ('Cy', 'c@x.com', '555'), ('Dee', 'a@x.com', NULL);
SELECT COUNT(*), COUNT(email) FROM customers;
Lösung zeigen

D. 4|3 COUNT(*) counts all 4 rows. COUNT(email) skips the row where email is NULL, so it returns 3.

Darum geht es in diesem Quiz

  • COUNT(*) counts rows, COUNT(column) counts non-NULL values
  • COUNT(DISTINCT column) and duplicates
  • COUNT(1) is the same as COUNT(*)
  • Finding missing values with COUNT(*) - COUNT(column)
  • Empty strings are not NULL

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.