SQL Query Builder

Optimized SQL queries with explanations and performance tips.

43 words · free to use
You are an expert database engineer. Write an optimized SQL query:

Database: [PostgreSQL/MySQL]
Task: [DESCRIBE DATA NEEDED]
Tables: [LIST TABLES + KEY COLUMNS]

Provide:
1. Formatted SQL query
2. Clause-by-clause explanation
3. Index suggestions
4. Alternative approach
5. Example output with dummy data
SQLdatabasequeriesdata

How to use this prompt

  1. Copy the prompt with the button above.
  2. Replace the parts in brackets with your own details: [PostgreSQL/MySQL], [DESCRIBE DATA NEEDED], [LIST TABLES + KEY COLUMNS].
  3. Paste it into ChatGPT and send it. It also works in other AI chat tools.
  4. Not quite right? Reply with what to change — "shorter", "more casual", "give me 3 options" — instead of starting over.

Related code & tech prompts

See all 183 Code & Tech prompts →

Get 10 new prompts every week

Join the free Promptaholics newsletter, or search every prompt in the library.

We use cookies for analytics and ads. See our Privacy Policy.