📊 Data & Analytics

AI2sql SQL Model — Query Generator

📁 Data & Analytics 👤 Contributed by @mergisi 🗓️ Updated
The prompt
Context: This prompt is used by AI2sql to generate SQL queries from natural language. AI2sql focuses on correctness, clarity, and real-world database usage. Purpose: This prompt converts plain English database requests into clean, readable, and production-ready SQL queries. Database: ${db:PostgreSQL | MySQL | SQL Server} Schema: ${schema:Optional — tables, columns, relationships} User request: ${prompt:Describe the data you want in plain English} Output: - A single SQL query that answers the request Behavior: - Focus exclusively on SQL generation - Prioritize correctness and clarity - Use explicit column selection - Use clear and consistent table aliases - Avoid unnecessary complexity Rules: - Output ONLY SQL - No explanations - No comments - No markdown - Avoid SELECT * - Use standard SQL unless the selected database requires otherwise Ambiguity handling: - If schema details are missing, infer reasonable relationships - Make the most practical assumption and continue - Do not ask follow-up questions Optional preferences: ${preferences:Optional — joins vs subqueries, CTE usage, performance hints}

Example outputs

Here is what ChatGPT, Claude, and Gemini typically return for this prompt:

🚀 ChatGPT

SELECT customers.customer_id, customers.name, SUM(orders.total_amount) AS total_spent FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id WHERE orders.order_date >= '2024-01-01' GROUP BY customers.customer_id, customers.name ORDER BY total_spent DESC LIMIT 10;

✨ Claude

SELECT c.customer_id, c.customer_name, COUNT(o.order_id) AS order_count, SUM(o.order_total) AS revenue FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id WHERE o.order_date BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY c.customer_id, c.customer_name HAVING COUNT(o.order_id) > 5 ORDER BY revenue DESC;

💎 Gemini

SELECT p.product_name, p.category, SUM(oi.quantity) AS units_sold, SUM(oi.quantity * oi.unit_price) AS total_revenue FROM products p INNER JOIN order_items oi ON p.product_id = oi.product_id GROUP BY p.product_id, p.product_name, p.category ORDER BY total_revenue DESC LIMIT 20;

How to use this prompt

Copy the prompt above or click an "Open in" button to launch it directly in your preferred AI. You can then customize the wording to match your exact use case — for example replacing placeholders like [your topic] with real context.

Which AI model works best

ChatGPT, Claude, and Gemini all produce useful results for this type of prompt. Claude is usually the most nuanced, ChatGPT the fastest, and Gemini the best when visual input or Google Workspace data is involved.

How to customize this prompt

Adapt the prompt to your specific use case. Replace placeholders (usually in brackets or caps) with your own context. The more detail you provide, the more precise the response.

Common use cases

  • Use directly in ChatGPT, Claude, or Gemini
  • Adapt to your specific project or industry
  • Use as a starting point for your own custom prompt
  • Compare across models to find the best fit for your case
  • Share with your team as a standard workflow

Variations

Adapt the tone (more casual, more technical), change the output format (bullet points vs. paragraphs), or add constraints (word limits, target audience).

Related prompts