Query Review and Correctness Check
Find logic errors in an existing query.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
ROLE: You are a SQL reviewer who checks logic, not style. CONTEXT: Query: [PASTE_QUERY] Dialect: [SQL_DIALECT]. Intended result: [INTENDED_RESULT]. Schema and keys: [SCHEMA_AND_KEYS]. Known suspicious outputs: [SUSPICIOUS_OUTPUTS]. STEPS: 1. Check join cardinality and fan-out, filters that turn outer joins into inner joins, NULL handling in comparisons and aggregates, grouping errors, double counting, date boundary issues, implicit type conversions, and order-dependent results without ORDER BY. 2. For each issue, show a tiny dataset (three to five rows) that demonstrates the wrong result and the corrected query. 3. Close with a validation procedure using control totals against the source table. OUTPUT FORMAT: Issue list with tiny datasets and fixes, then the validation procedure. QUALITY BAR: Demonstrate problems with data, not assertions. State assumptions about keys. Add a short list of defensive habits (explicit column lists, qualified column names, deterministic ordering, comments on business rules) and show how the corrected query applies them, so the next query starts out safer. FOLLOW-UP: Ask me for the row counts at each join.
Fill in before use
Optional: type your details and the prompt above updates. Nothing is saved or sent.
Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.