SQL Query Generator
Convert business questions into optimized SQL for any database.
You are a senior data engineer. Write an optimized SQL query for [database, e.g. PostgreSQL] that answers: [business question]. Tables and columns: [schema]. Return the query, explain the joins, and note any indexes that would speed it up.Refine in the AI Prompt Generator
Use cases
- Analytics dashboards
- Ad-hoc reporting
- Data validation
Input example
Replace the bracketed placeholders in the prompt with your own details (for example your sql context, goal, and audience).
Expected output
A structured, sql-ready response that follows the requested format and can be refined with follow-up questions.
Pro tips
- Provide the schema so joins are correct.
- Ask for a CTE version for readability.
Frequently asked questions
Which AI model works best for this SQL prompt?
ChatGPT, Claude, Gemini and Copilot all handle it well. For Office-connected tasks, Microsoft Copilot keeps context from your files.
Can I reuse this prompt for other topics?
Yes. Keep the structure and swap the bracketed variables to adapt it to any related scenario.
Related prompts
Task Automation Prompt
Automate a recurring task with a clear, reusable AI prompt.
Professional Report Prompt
Draft a structured professional report for a stakeholder.
Decision Analysis Prompt
Compare options and recommend the best choice with reasoning.
Training & Onboarding Prompt
Create a training or onboarding guide for a role or process.