Back to Prompt Library
Coding
SQLCodingDatabase

SQL Query Generator and Explainer

Writes and explains SQL queries for any database type.

Prompt Template

Generate a SQL query to [DESCRIBE WHAT YOU WANT TO RETRIEVE OR DO]. The database uses [DATABASE TYPE — PostgreSQL/MySQL/SQLite]. Relevant tables and their key columns: [LIST TABLES AND COLUMNS]. Requirements: [ANY SPECIFIC REQUIREMENTS — filtering, ordering, joining, aggregating]. After writing the query, explain each clause in plain English so a non-developer could understand what it does. Then suggest one optimization if applicable.

How to use this prompt

  1. Copy the prompt template using the button above.
  2. Paste it into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.).
  3. Replace all bracketed placeholders like [TOPIC] with your specific details.
  4. Send the prompt and refine the output as needed.
Advertisement