SQL Query Writer

Research & Analysischatgpt-prompts-for-data-analysisdatabase_typebusiness_questiontable_schema

Providing the full schema and relationships eliminates guesswork. Asking for comments and assumption flags makes the output reviewable and trustworthy before running against production.

Prompt
Write a SQL query for {{database_type}} to answer this question: "{{business_question}}"

Table schema:
{{table_schema}}

Table relationships:
{{relationships}}

Requirements:
- Use clear aliases for all tables and columns
- Add comments explaining each major section of the query
- Handle NULL values appropriately
- Optimize for readability over cleverness
- If the query requires aggregation, include a GROUP BY with the most useful breakdown
- Return results ordered by {{order_preference}}

After the query, explain what each section does and flag any assumptions you made about the data.

Variables to customize

{{database_type}}{{business_question}}{{table_schema}}{{relationships}}{{order_preference}}

Why this prompt works

Providing the full schema and relationships eliminates guesswork. Asking for comments and assumption flags makes the output reviewable and trustworthy before running against production.

What you get when you save this prompt

Your workspace unlocks powerful tools to iterate and improve.

AI OPTIMIZE

AI Optimization

One-click improvement with structure analysis and pattern suggestions.

VERSION DIFF

Version History

Track every edit. Compare versions side-by-side with word-level diffs.

ORGANIZE
Development
Code Review
Testing
Marketing

Folders & Tags

Organize your library with nested folders, tags, and drag-and-drop.

MCP
$ npm i -g @promptingbox/mcp
Claude · Cursor · ChatGPT

Use Everywhere

Access prompts from Claude, Cursor, ChatGPT & more via MCP integration.

Your prompts, organized

Save, version, and access your best prompts across ChatGPT, Claude, Cursor, and more.