Describe your tables and the question you want answered. Get an optimized SQL query with explanations for each clause.
List your table names, columns, and what you want to find out. The AI writes the SQL and explains the logic.
Write a SQL query to answer my business question. Explain each part so I understand the logic. Database type: [MYSQL / POSTGRESQL / SQLITE / SQL SERVER / BIGQUERY] My tables: [DESCRIBE YOUR TABLES, e.g.: - orders (order_id, customer_id, product_id, order_date, amount, status) - customers (customer_id, name, email, signup_date, region) - products (product_id, name, category, price)] What I want to find out: [YOUR QUESTION IN PLAIN ENGLISH, e.g., "Show me the top 10 customers by total spend in the last 6 months, along with how many orders they placed and their most purchased product category"] Provide: 1. The complete SQL query, properly formatted and indented 2. A line-by-line explanation of what each clause does and why 3. Expected output format (what the result columns will look like) 4. Performance tips (indexes that would help, potential bottlenecks) 5. Two variations: one simpler version if I need a quick answer, one advanced version with additional insights 6. Common mistakes to avoid with this type of query
"SQL Query Generator" works by removing ambiguity from the AI interaction. Instead of hoping the model guesses your intent, this well-structured prompt defines the task boundaries explicitly. You can expect actionable analytical insights with methodology documentation and visualization recommendations - the kind of result that normally requires several rounds of prompt refinement.
These data analysis tips will help you get stronger results when using "SQL Query Generator" and similar prompts in this category.
"SQL Query Generator" is particularly useful in these situations. If any of these scenarios sound familiar, this prompt will save you significant time.
When you use "SQL Query Generator" with ChatGPT, Claude, or Gemini, here is what to expect in the AI output.
Adapt "SQL Query Generator" to your specific situation by modifying these key areas. The more context you add, the better the results.