SQL From a Business Question

A documented SQL query with its assumptions and a way to sanity-check the output.

Intermediate · Works with ChatGPT, Claude, Gemini, Copilot

The prompt

Write a SQL query that answers this question, with comments explaining each join and filter.

State the assumptions you're making about the schema and grain of the tables, and suggest one validation check to run against the result before trusting it.

The schema or tables available:
{{DATA}}

The question the query should answer:
{{QUESTION}}

Why this prompt works

Naming a validation check up front catches double-counted joins before the number gets repeated as fact.

How to customize it

  • Include primary/foreign key relationships, not just column names
  • Ask for the check that would catch the most common failure mode: duplicated rows from a join

Common mistakes

  • Leaving out the grain of each table, which is the usual cause of silent duplication
  • Running the query without the suggested sanity check

Example

Input

Schema or tables available: orders(id, customer_id, total, created_at); customers(id, region)

What a good answer looks like

A commented SQL query, its stated assumptions, and one specific number or row-count check to confirm it's right.

Make this prompt fit your work

ModelCoach.ai scores your version, shows what to improve and explains why, right inside ChatGPT, Claude, Gemini and Copilot.

Related prompts