Quiz di SQL: 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.

Medio 10 domande ~6 minuti Superato con il 80% SQLite

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 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;
Mostra la risposta

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".

Cosa copre questo 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

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.