SQL-Quiz: EXISTS vs IN

This SQL quiz compares EXISTS and IN subqueries and their negated forms. You will see why NOT IN returns no rows when the list contains a NULL, how NOT EXISTS avoids it and what really differs between the two in modern databases.

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 print?

CREATE TABLE customers (id INTEGER, name TEXT);
CREATE TABLE orders (id INTEGER, customer_id INTEGER);
INSERT INTO customers VALUES (1, 'Ann'), (2, 'Bob'), (3, 'Cy');
INSERT INTO orders VALUES (10, 1), (11, 1), (12, 3);
SELECT name
FROM customers c
WHERE EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.id)
ORDER BY name;
Lösung zeigen

B. Ann Cy EXISTS is true when the correlated subquery finds at least one row for that customer. Like IN, it never repeats a customer, no matter how many orders match.

Darum geht es in diesem Quiz

  • EXISTS (correlated subquery) and its select list
  • IN vs EXISTS for semi-joins
  • The NOT IN with NULL trap
  • Fixing it with NOT EXISTS or IS NOT NULL
  • How optimizers treat IN and EXISTS

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.