Back to Blog

Introducing AI-Powered SQL: Write Queries in Plain English

October 12, 2025By Timothy Murphy
Introducing AI-Powered SQL: Write Queries in Plain English

We're excited to announce the biggest update to LunoDB yet: AI-powered database assistance. Say goodbye to memorizing SQL syntax and hello to writing queries in plain English.

What's New?

LunoDB now includes powerful AI features that understand your database schema and help you work faster than ever before.

1. Natural Language to SQL

Simply describe what you want in plain English, and our AI will write the SQL for you:

You type: "Show me all users who signed up in the last 30 days"

AI generates:

SELECT * FROM users
WHERE created_at >= DATE_SUB(NOW(), INTERVAL 30 DAYS)
ORDER BY created_at DESC;

The AI understands your database structure, including table names, column names, and relationships, so the queries it generates are accurate and optimized for your specific schema.

2. Schema-Aware Suggestions

The AI knows your entire database structure:

  • All table names and their relationships
  • Column names and data types
  • Foreign key constraints
  • Indexes and primary keys

This means it can suggest the most efficient queries and even warn you about potential issues before you run them.

3. Query Explanation

Don't understand what a query does? Just ask! The AI can:

  • Explain complex queries in simple terms
  • Break down JOIN operations
  • Clarify WHERE conditions
  • Suggest optimizations

4. Multi-Provider Support

Choose from multiple AI providers:

  • OpenAI GPT-5 - Most capable, best for complex queries
  • Anthropic Claude - Great balance of speed and quality
  • Google Gemini - Fast and efficient
  • Ollama - Run AI locally on your machine (no internet required!)

How to Use It

Step 1: Configure Your AI Provider

Go to Settings → AI and choose your preferred provider. You can use:

  • Cloud providers (OpenAI, Anthropic, Google) with your API key
  • Local AI with Ollama (completely free and private)

Step 2: Open the AI Assistant

Click the AI button in the query editor or press Cmd/Ctrl + K to open the AI assistant.

Step 3: Describe What You Want

Type your request in plain English. Be as specific as you want:

  • "Find all orders over $100 from the last week"
  • "Show me users who haven't logged in for 90 days"
  • "Calculate total revenue by month for 2024"
  • "Join customers with their orders and show total spent"

Step 4: Review and Run

The AI will generate the SQL query. You can:

  • Review it before running
  • Ask for modifications ("add a limit of 10")
  • Request explanations ("why did you use LEFT JOIN?")
  • Run it directly

Real-World Examples

Example 1: Complex Analytics Query

Request: "Show me the top 10 products by revenue in each category for Q4 2024"

Generated SQL:

WITH product_revenue AS (
    SELECT
        p.category_id,
        p.product_id,
        p.name,
        SUM(oi.quantity * oi.price) as revenue,
        ROW_NUMBER() OVER (
            PARTITION BY p.category_id
            ORDER BY SUM(oi.quantity * oi.price) DESC
        ) as rank
    FROM products p
    JOIN order_items oi ON p.product_id = oi.product_id
    JOIN orders o ON oi.order_id = o.order_id
    WHERE o.created_at >= '2024-10-01'
      AND o.created_at < '2025-01-01'
    GROUP BY p.category_id, p.product_id, p.name
)
SELECT * FROM product_revenue WHERE rank <= 10;

Example 2: Data Cleanup

Request: "Find duplicate email addresses in the users table"

Generated SQL:

SELECT email, COUNT(*) as count
FROM users
GROUP BY email
HAVING COUNT(*) > 1
ORDER BY count DESC;

Example 3: Performance Analysis

Request: "Show me slow queries from the last hour"

Generated SQL:

SELECT
    query_time,
    lock_time,
    rows_examined,
    sql_text
FROM mysql.slow_log
WHERE start_time >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
ORDER BY query_time DESC
LIMIT 20;

Privacy & Security

Your privacy matters:

  • Local AI Option: Use Ollama to run AI completely on your machine - no data sent to the cloud
  • Schema Only: We only send table/column names to AI providers, never your actual data
  • API Key Control: Your API keys are stored locally and encrypted
  • No Training: Your queries are never used to train AI models

Tips for Best Results

  1. Be Specific: "Show users from California who signed up this month" works better than "show some users"

  2. Mention Table Names: If you know them, include table names: "from the orders table"

  3. Ask for Explanations: Don't understand the generated query? Just ask "explain this query"

  4. Iterate: Start simple, then refine: "add a filter for active users only"

  5. Review Before Running: Always review AI-generated queries, especially for UPDATE or DELETE operations

Performance Impact

The AI features are designed to be fast:

  • Query generation: typically under 2 seconds
  • Zero impact on query execution
  • Works offline with Ollama
  • No slowdown to your existing workflows

What's Next?

This is just the beginning. We're working on:

  • Database design suggestions
  • Automatic index recommendations
  • Query optimization tips
  • Data migration helpers
  • Natural language data exports

Get Started Today

The AI features are available now in LunoDB v1.7.0 and later. Update to the latest version and give it a try!

Have questions or feedback? We'd love to hear from you. Reach out on Twitter @lunodb_app or email us at [email protected].

Happy querying! 🚀