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

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 name
FROM customers c
WHERE EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.id)
ORDER BY name;
Mostra la risposta

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.

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

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.