Skip to content
New this week26 prompts for Sora, Veo and Runway video workflows.
Explore video prompts→
AIPrompt123Prompt library

Search AIPrompt123

Search prompts, categories, platforms and repositories

Coding & DeveloperIntermediate

Write a SQL query from a business question

This copy-ready coding prompt helps you write a SQL query from a business question with fewer blank-page decisions. Paste it into ChatGPT and Claude, fill the variables, and you get a structured first draft you can edit. It is written for repeatable results and tells you what to check before publishing.

4.8(36 ratings)1.1k copies
Updated By Site Admin
44 words · v1.2

Fill in the blanks · 2 variables

ChatGPT promptReplace every highlighted token before sending
Write a PostgreSQL query that answers: {question}. Use the schema below. Explain the join logic, filters and grain before the SQL. Add a version with a CTE for readability and a note on indexes that would help. Do not use SELECT *.

Schema:
{schema}

---
Platform note: Work through the task step by step, then give the final answer in the requested format. Ask one clarifying question if a required detail is missing.
Open in ChatGPT

Comments

Share what worked, what broke and which model you used. Comments appear after posting and are moderated for spam.

Saved with an anonymous browser ID. No login needed.

How to use this prompt

  1. 1

    Open ChatGPT and start a new chat. Paste the prompt exactly as written.

  2. 2

    Replace each placeholder ({question}, {schema}) with your own details. Leave the instructions and the output format untouched.

  3. 3

    Add one concrete example or data point if the model's first answer is vague. Specific input produces specific output.

  4. 4

    Run it once, then ask for a single revision with a specific critique rather than regenerating from scratch.

  5. 5

    Review the result. Reproduce the bug, review the diff and run the tests in a clean environment.

Worked example

This is the kind of input the prompt expects and the shape of output it produces. Your result will differ with the model and the details you supply.

Example input

Question: Which plan has the highest 90-day retention? Schema: users(id, created_at, plan); events(user_id, name, created_at)

Example output

**Diagnosis:** the handler reads `req.body` before the JSON middleware runs, so the body is undefined on POST requests. **Fix:** move the middleware above the route registration and add a guard for missing bodies. No public API changes. **Verification:** added a failing test for an empty JSON body, confirmed it fails, applied the fix, then ran the full suite. The test now passes and the unrelated snapshot tests are unchanged.

Tips for a better result

  • Paste the full error and the smallest relevant code, not a screenshot of the stack trace.
  • Ask for a plan before allowing multi-file edits; it prevents sprawling refactors.
  • Require a failing test first and a verification command at the end.
  • Change one variable at a time and compare the outputs; it is the fastest way to learn what this model responds to.

Common mistakes

  • Accepting a confident fix without reproducing the bug or running tests.
  • Letting the assistant rewrite entire files when a three-line diff would do.
  • Pasting secrets, tokens or customer data into a hosted model.
Verified Knowledge · FAQ

Questions about this prompt

Practical answers about running the write a sql query from a business question prompt.

Related prompts

Same job, a different angle — or the next step in the workflow.

Coding & Developer
Intermediate

Write a coding interview practice plan

This copy-ready coding prompt helps you write a coding interview practice plan with fewer blank-page decisions. Paste it into ChatGPT and Claude, fill the variables, and you get a structured first draft you can edit. It is written for repeatable results and tells you what to check before publishing.

ChatGPTClaude
4.8(84)1.1k copies

Write a seed script for a database

This copy-ready coding prompt helps you write a seed script for a database with fewer blank-page decisions. Paste it into ChatGPT and Cursor, fill the variables, and you get a structured first draft you can edit. It is written for repeatable results and tells you what to check before publishing.

ChatGPTCursor
4.8(48)1.1k copies

Fix a flaky test

This copy-ready coding prompt helps you fix a flaky test with fewer blank-page decisions. Paste it into Cursor and Claude, fill the variables, and you get a structured first draft you can edit. It is written for repeatable results and tells you what to check before publishing.

CursorClaude
4.8(54)1.0k copies

Written and reviewed by Site Admin

Author & Platform Administrator

Administrator and lead editor at AIPrompt123, curating high-performance AI prompts, SEO/AEO/GEO strategies, and developer repositories.

Last reviewed 12 February 2026 · version 1.2 · tested on ChatGPT, Claude, DeepSeek