SQL-Quiz: Join Pitfalls

This SQL quiz collects the join mistakes that produce wrong numbers without any error. You will see a LEFT JOIN turned into an inner join by WHERE, totals multiplied by fan-out, NULL keys that never match and other traps that show up in real reports and interviews.

Schwer 10 Fragen ~8 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

The goal is every customer, with their big orders if any. What does this print?

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

A. Ann WHERE runs after the join, and for Bob o.amount is NULL, so NULL > 20 is not true and his row is dropped (Cy's 5 fails too). A condition on the right table in WHERE turns the left join into an inner join.

Darum geht es in diesem Quiz

  • Filtering a LEFT JOIN in WHERE vs in ON
  • Fan-out when joining two one-to-many tables
  • Why NULL keys never match
  • A later INNER JOIN undoing a LEFT JOIN
  • SUM(DISTINCT) and duplicate rows

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.