The query runs and returns rows. Nobody, including you, can say whether the numbers are right. That is the most annoying part of SQL: the database never tells you when you asked the wrong question. These six ChatGPT prompts for SQL queries put the effort where it belongs, in the front half where you describe the tables and define the grain, and in the back half where you try to break your own result before a report depends on it.
Step 1 — Describe the tables and pin down the question
1. Schema briefing
Here are my table definitions: [paste CREATE TABLE statements]. For [database engine], summarize each table's grain in one line, list the keys, and flag the columns that look like they hold the same information under different names. Then list the joins you expect to be dangerous and why.
What it does: Finds the ambiguity in your schema before it becomes a wrong number.
How to use: Replace [paste CREATE TABLE statements] and [database engine]. Paste real definitions, not a summary you typed from memory.
2. Question to specification
Turn this request into a query specification: [the question in plain language]. Fill in the output grain, the time window, the filters, the definition of [metric], and how to treat rows with missing values. Ask me about anything you had to guess.
What it does: Converts a vague ask into a written spec you can check with the person who asked.
How to use: Replace the question and [metric]. Send the spec back for a one-line confirmation before writing any SQL.
3. Join path check
I need [columns] from [table A] and [table B], filtered to [time window]. Walk the join path step by step, and at each hop tell me whether the row count should stay the same or grow. Name the hop most likely to duplicate rows and the test that would catch it.
What it does: Makes row multiplication visible before it inflates your totals.
How to use: Replace [columns], both tables, and [time window]. Keep the row-count expectations; you will check them against the real query in step 2.
Step 2 — Write the query, then try to break it
4. The query, annotated
Write the SQL for this specification: [paste spec]. Use [database engine] syntax, one clause per line, and a comment above each join and each filter explaining the business reason. No subquery nesting deeper than two levels. If the spec is ambiguous, stop and ask rather than guessing.
What it does: Produces SQL a colleague can review without opening your head.
How to use: Replace [paste spec] and [database engine]. Run it with a limit first and read the columns before you trust the totals.
5. Attempt to falsify the result
Here is my query and its output: [paste query and first 20 rows]. Write five check queries that would prove this result wrong: duplicate keys, nulls in a join column, totals that fail a known subtotal, rows outside [time window], and a case where the filter excludes the largest group. Say what each check should return.
What it does: Gives you evidence instead of confidence.
How to use: Replace the query, the sample rows, and [time window]. Expect at least one check to fail on the first pass; that is the point.
6. Slow query review
This query runs slowly: [paste query and the query plan]. For [database engine], name the operation doing the most work, suggest the index that would help, and rewrite the query if the structure is the problem. Tell me which change I should test first and what improvement would confirm it.
What it does: Turns a plan you cannot read into one change worth testing.
How to use: Replace the query, the plan, and [database engine]. Change one thing at a time, otherwise you learn nothing from the result.
Common mistakes
- Writing the query before deciding what one row should represent, which makes every total a guess.
- Using SELECT star while debugging, so a duplicated join column hides in plain sight.
- Trusting a result because it looks plausible, then discovering the filter dropped a whole segment.
Keep going
- More Coding prompts
- 5 Claude Prompts for Python Scripts (Copy & Paste)
- 5 ChatGPT Prompts for Value Propositions
Every prompt on GuPrompt is free to copy — no signup, no paywall.