data•6 prompts
SQL Query Prompts
SQL is how you talk to databases. These prompts help you write queries that get the data you need, efficiently and correctly.
1. Query from Description
Best: ClaudeWrite a SQL query for: [describe what you want in plain English]. My tables: [list tables and key columns]. Database: [PostgreSQL/MySQL/etc.]. Include comments explaining the logic.
Include table relationships. Claude needs to know how tables connect.
2. Complex Join
Best: ClaudeHelp me write a query joining these tables: [list tables and relationships]. I need: [columns from each]. Watch for: [duplicates, missing data, etc.]. Explain the join logic and potential gotchas.
Wrong joins are silent errors. Think through what each join produces.
3. Aggregate Analysis
Best: ClaudeWrite a query to analyze [metric] by [dimensions]. Include: grouping, filtering (WHERE and HAVING), and ordering. I want to see: [describe desired output]. Add window functions if helpful.
GROUP BY is powerful. Combine with HAVING for filtered aggregates.
4. Query Optimization
Best: ClaudeOptimize this slow query: [paste query]. It runs on [describe table sizes]. Suggest: index additions, query restructuring, and alternative approaches. Explain why each change helps.
Slow queries often need better indexes or restructured logic. Check EXPLAIN output.
5. Debug Query
Best: ClaudeThis query isn't returning what I expect: [paste query]. Expected: [describe]. Actual: [describe]. Help me find the bug. Walk through the logic step by step and identify where it goes wrong.
Debug by running subqueries. Find where results diverge from expectations.
6. Migrate Query
Best: ClaudeConvert this [source database] query to [target database]: [paste query]. Handle: syntax differences, function name changes, and any features that don't translate directly.
Database-specific functions trip up migrations. Test thoroughly.
Try These Prompts with Multiple AIs
Get responses from Claude, ChatGPT, Gemini, and more—all at once. Compare which AI handles these prompts best.
Try Council Free