SQL: Find the Bug

This SQL quiz shows queries with a comment saying what they were meant to do, and asks what they really return or what is wrong. The bugs are the ones that slip into real code and interviews, like operator precedence, join fan-out, integer division and subqueries that quietly match everything.

Difícil 10 perguntas ~8 minutos Aprovação com 80% SQLite

Escolha um modo

Jogando como visitante: entre para guardar seu XP e sua sequência.

Pergunta de exemplo

Pergunta 1 de 10

The query below has a bug. What does it print?

CREATE TABLE products (name TEXT, category TEXT, price INTEGER);
INSERT INTO products VALUES
  ('pen', 'office', 2), ('desk', 'office', 300),
  ('tv', 'tech', 500), ('cable', 'tech', 5);
-- meant: cheap items (price < 10) in office or tech
SELECT COUNT(*) FROM products
WHERE category = 'office' OR category = 'tech' AND price < 10;
Mostrar a resposta

B. 3 AND binds tighter than OR, so this means office OR (tech AND price < 10): pen, desk and cable. Add parentheses, (category = 'office' OR category = 'tech') AND price < 10, or use category IN ('office', 'tech'), to get the intended 2.

O que este quiz cobre

  • AND/OR precedence and date range edges
  • COUNT(*) with LEFT JOIN, and join fan-out in SUM
  • Integer division in percentages
  • Ambiguous columns, UNION mismatches and quoting
  • Subqueries and window functions used in the wrong place

Perguntas frequentes

Preciso de uma conta?

Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.

Posso refazer?

Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.