SQL-Quiz: LEFT JOIN

This SQL quiz is about LEFT JOIN and the NULLs it brings with it. You will count matches without losing unmatched rows, find rows that have no partner and see how COUNT, SUM and table order behave with outer joins.

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 c.name, COUNT(o.id)
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.id, c.name
ORDER BY c.name;
Lösung zeigen

C. Ann|2 Bob|0 Cy|1 The left join keeps Bob with NULL order columns. COUNT(o.id) skips NULLs, so Bob's count is 0, which is exactly what you want for "orders per customer".

Darum geht es in diesem Quiz

  • Keeping unmatched rows from the left table
  • COUNT(*) vs COUNT(column) after a LEFT JOIN
  • Finding rows with no match using IS NULL
  • NULL sums and COALESCE
  • RIGHT and FULL OUTER JOIN in SQLite, MySQL and PostgreSQL

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.