Skip to content

Best AI · SQL

The best AI for SQL

In our test runs of September 27, 28, 29 and October 2, 7, 8, 9, 15, 2026, 20 of the 20 models passed 5 of 5 SQL prompts, so these prompts don't name one best model. For best value, GLM 5.3 (5 of 5). Our picks below follow fixed rules, beside each model's price per message, and every prompt and reply is published.

Based on 100 of our test runs on , through OpenRouter with the app's own prompt and settings. Updated .

Short answer

In our test runs on October 15, 2026, all 20 models passed 5 of 5 SQL prompts, so these prompts don't pick one for hard problems. For value, GLM 5.3 (5 of 5), 250 a month on Pro; for everyday SQL, GPT-6 Luna (5 of 5), from the daily count.

Our picks for SQL

  • Hard problems

    Shared by 20 models

    All 20 models passed 5 of 5, both hard ones: Claude Fable 5.1, Claude Opus 5.5, Claude Sonnet 5.5 and 17 more. These prompts don't tell them apart, so they share the pick.

  • Best value

    GLM 5.3

    Passed 5 of 5 SQL prompts, with 250 a month on Pro.

  • Everyday

    GPT-6 Luna

    Passed 5 of 5 SQL prompts; an everyday model, so its messages come from the daily count (60 a day on Pro), not the monthly allowance.

These picks aren't our opinion: they're what the results below give, by these rules, among all 20 models in llmwise. They change when the results do.

  • Hard problems: the model that passed the most prompts and, of those, the most hard ones. Models level on both share the pick: the prompts don't tell them apart, so we don't break the tie by price or by name.
  • Best value: among the models that draw on the monthly allowance, the one with the most messages on Pro that passed no more than one prompt fewer than the top model. Ties go to the one that passed more, then to the lower cost per reply.
  • Everyday: among the cheapest models on the page (the everyday models, which come from the daily count, when the page has any), the one that passed the most. Ties go to the one that passed more of the hard prompts, then to the lower cost per reply.

Our SQL test runs, model by model

How each model did on our 5 SQL prompts, what each reply counted as on Pro, and what it cost to run.

Our SQL test runs
ModelPassedHard onesMessages used on ProCost per replyTime per reply
Claude Fable 5.1Anthropic5 of 52 of 21 each, of 31 a month on Pro$0.01854.5 s
Claude Opus 5.5Anthropic5 of 52 of 21 each, of 62 a month on Pro$0.00924.4 s
Claude Sonnet 5.5Anthropic5 of 52 of 21 each, of 125 a month on Pro$0.00381.9 s
Claude Sonnet 5Anthropic5 of 52 of 21 each, of 125 a month on Pro$0.00282.5 s
Claude Haiku 5.5Anthropic5 of 52 of 21 each, of 60 a day on Pro$0.00021.6 s
Claude Haiku 4.5Anthropic5 of 52 of 21 each, of 250 a month on Pro$0.00101.4 s
GPT-6 AstraOpenAI5 of 52 of 21 each, of 31 a month on Pro$0.00982.8 s
GPT-6.1 SolOpenAI5 of 52 of 21 each, of 125 a month on Pro$0.00102.0 s
GPT-6 SolOpenAI5 of 52 of 21 each, of 125 a month on Pro$0.00211.9 s
GPT-6 LunaOpenAI5 of 52 of 21 each, of 60 a day on Pro$0.00011.5 s
Gemini 4 ArgonGoogle5 of 52 of 21 each, of 62 a month on Pro$0.00123.1 s
Gemini 3.1 Pro (preview)Google5 of 52 of 21 each, of 125 a month on Pro$0.00777.3 s
Gemini 3.8 FlashGoogle5 of 52 of 21 each, of 250 a month on Pro$0.00073.6 s
DeepSeek V4.1 FlashDeepSeek5 of 52 of 21 each, of 60 a day on Pro$0.00020.7 s
DeepSeek V4 ProDeepSeek5 of 52 of 21 each, of 250 a month on Pro$0.00207.4 s
Grok 4.7xAI5 of 52 of 21 each, of 250 a month on Pro$0.00486.1 s
Kimi K3Moonshot5 of 52 of 21 each, of 125 a month on Pro$0.00241.9 s
GLM 5.3Z.ai5 of 52 of 21 each, of 250 a month on Pro$0.00031.5 s
GLM 5.3 FlashZ.ai5 of 52 of 21 each, of 60 a day on Pro$0.00011.7 s
Mistral Large 4Mistral5 of 52 of 21 each, of 250 a month on Pro$0.00229.3 s
Passed: out of the job's 5 prompts, how many replies passed their check (a reply the provider failed to give isn't counted). Messages used: what each reply counted as on Pro, and Pro's count on the model. Cost: what OpenRouter charged us per reply, on average; in llmwise you pay per message, not per token. Time: from sending to the whole reply.

One prompt, side by side

Each model's reply to “Every customer, even those without orders”, as it came, with whether it passed and what it cost.

The prompt: Every customer, even those without orders (hard)
An online shop's SQLite database:
CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT NOT NULL, country TEXT NOT NULL, signed_up TEXT NOT NULL);
CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT NOT NULL, category TEXT NOT NULL, price_cents INTEGER NOT NULL);
CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER NOT NULL REFERENCES customers(id), ordered_on TEXT NOT NULL, status TEXT NOT NULL);
CREATE TABLE order_items (order_id INTEGER NOT NULL REFERENCES orders(id), product_id INTEGER NOT NULL REFERENCES products(id), quantity INTEGER NOT NULL);

For every customer, show their name, the date of their first order that wasn't cancelled, and how many orders that weren't cancelled they have. Include customers who have no such orders, with NULL for the date and 0 for the count. Sort by name.
Write one SQLite query and reply with it in a ```sql code block.
  • Claude Fable 5.1

    Passed: Returned the right 8 rows.

    ```sql
    SELECT c.name,
           MIN(o.ordered_on) AS first_order_date,
           COUNT(o.id)       AS order_count
    FROM customers c
    LEFT JOIN orders o
           ON o.customer_id = c.id
          AND o.status <> 'cancelled'
    GROUP BY c.id, c.name
    ORDER BY c.name;
    ```
    
    The status filter is in the `ON` clause (not `WHERE`) so customers with only cancelled orders or no orders are still kept, yielding `NULL` and `0`.

    861 tokens in, 185 out · 5.2 s · $0.0199 · 1 message on Pro · answered by anthropic/claude-fable-5.1 via Anthropic ·

  • GLM 5.3

    Passed: Returned the right 8 rows.

    ```sql
    SELECT c.name,
           MIN(o.ordered_on) AS first_order_date,
           COUNT(o.id) AS order_count
    FROM customers c
    LEFT JOIN orders o
      ON o.customer_id = c.id AND o.status != 'cancelled'
    GROUP BY c.id, c.name
    ORDER BY c.name;
    ```

    562 tokens in, 68 out (1 of them reasoning) · 1.0 s · $0.0007 · 1 message on Pro · answered by z-ai/glm-5.3 via Wafer ·

  • GPT-6 Luna

    Passed: Returned the right 8 rows.

    ```sql
    SELECT
      c.name,
      MIN(CASE WHEN o.status <> 'cancelled' THEN o.ordered_on END) AS first_order_date,
      COUNT(CASE WHEN o.status <> 'cancelled' THEN o.id END) AS order_count
    FROM customers AS c
    LEFT JOIN orders AS o
      ON o.customer_id = c.id
    GROUP BY c.id, c.name
    ORDER BY c.name;
    ```

    522 tokens in, 92 out · 2.4 s · $0.0001 · 1 message on Pro · answered by openai/gpt-6-luna via OpenAI ·

The SQL prompts, and how they're scored

Query result. Automatic. The query runs against a small SQLite database and must return the same rows as our reference query (column names and order don't matter; row order does when the prompt asks for it).

Each prompt was sent the way llmwise sends a message in a side-by-side comparison, which offers no tools: the app's own system prompt, the model's own settings, and Pro's reply size limit (8,000 tokens). Read all five SQL prompts and how every reply was scored.

Prompts like these to try yourself

What matters for SQL

  • Knowing your schema

    Without your schema a model guesses table and column names. With it, most queries come out right first time.

  • The right dialect

    Date functions, string handling and upserts differ between databases. Say which one you use.

  • Correctness

    A query that runs isn't always a query that's right. Test it on sample data before running it on production.

Every model at a glance

Every model in llmwise
ModelOn ProOn FreeContext windowImagesPDFsReasoningAPI price per 1M, in / out
Claude Fable 5.1Anthropic31/mo on ProNo1M tokensYesWhole fileYes$10.00 / $50.00
Claude Opus 5.5Anthropic62/mo on ProNo1M tokensYesWhole fileYes$4.00 / $20.00
Claude Sonnet 5.5Anthropic125/mo on ProNo1M tokensYesWhole fileYes$2.00 / $10.00
Claude Sonnet 5Anthropic125/mo on ProNo1M tokensYesWhole fileYes$2.00 / $10.00
Claude Haiku 5.5Anthropic60/day on ProYes1M tokensYesWhole fileYes$0.10 / $0.50
Claude Haiku 4.5Anthropic250/mo on ProNo200K tokensYesWhole fileNo$1.00 / $5.00
GPT-6 AstraOpenAI31/mo on ProNo1.05M tokensYesWhole fileYes$10.00 / $50.00
GPT-6.1 SolOpenAI125/mo on ProNo1.05M tokensYesWhole fileYes$2.00 / $10.00
GPT-6 SolOpenAI125/mo on ProNo1.05M tokensYesWhole fileYes$2.00 / $10.00
GPT-6 LunaOpenAI60/day on ProNo1.05M tokensYesWhole fileYes$0.10 / $0.50
Gemini 4 ArgonGoogle62/mo on ProNo1.05M tokensYesWhole fileYes$4.00 / $20.00
Gemini 3.1 Pro (preview)Google125/mo on ProNo1.05M tokensYesWhole fileYes$2.00 / $12.00
Gemini 3.8 FlashGoogle250/mo on ProNo1.05M tokensYesWhole fileYes$0.75 / $3.75
DeepSeek V4.1 FlashDeepSeek60/day on ProNo1.05M tokensYesText onlyYes$0.30 / $1.20
DeepSeek V4 ProDeepSeek250/mo on ProNo1.05M tokensNoText onlyYes$0.40 / $4.00
Grok 4.7xAI250/mo on ProNo500K tokensYesWhole fileYes$2.00 / $6.00
Kimi K3Moonshot125/mo on ProNo1.05M tokensYesText onlyYes$3.00 / $15.00
GLM 5.3Z.ai250/mo on ProNo1.05M tokensNoText onlyYes$1.40 / $4.40
GLM 5.3 FlashZ.ai60/day on ProNo1.05M tokensYesText onlyYes$0.15 / $0.50
Mistral Large 4Mistral250/mo on ProNo1.05M tokensYesText onlyYes$0.68 / $2.09
Each badge is how many messages Pro gets on the model: a month’s, or a day’s on an everyday model. Free is a one-time trial of 5 messages on the models marked. “Text only” models get the text of a PDF, not the file. API prices are the per-token prices in our model catalog as of October 2026 (Anthropic: Anthropic's list price; OpenAI: OpenAI's list price; Google: Google's list price; DeepSeek: the price of the OpenRouter endpoints llmwise uses, not DeepSeek's own API; xAI: xAI's price, served through OpenRouter; Moonshot: Moonshot's list price; Z.ai: Z.ai's list price; Mistral: Mistral's price, served through OpenRouter). In llmwise you pay per message, not per token. Claude Haiku 5.5: the rate for prompts up to 100K tokens; $0.50 / $2.50 a million over that. Gemini 4 Argon: its standard price from December 1, 2026; $2 / $10 until then. Gemini 3.1 Pro (preview): the standard rate, for prompts up to 200K tokens. Gemini 3.8 Flash: an introductory price, through December 31, 2026. Grok 4.7: xAI charges more for very long prompts. Mistral Large 4: a sale price, half its list price of $1.36 / $4.18.

Every limit is published. Paid plans also have a monthly fair-use limit on AI cost: Plus $3.75, Pro $7.50, Max $20, Ultra $42, Studio $85. Using every message on your plan at typical sizes stays under it; very large messages and heavy research use it faster. Every limit, explained.

SQL in llmwise

  • Your schema in the chat

    Paste your CREATE TABLE statements or attach them as a text file, so queries use your real table and column names.

  • Test queries (Pro and higher plans)

    On Pro and higher plans the model can test a query: for example, load a CSV you attach into SQLite with Python and run it. A run counts as 1 Claude Haiku 4.5 message.

  • Queries as documents

    Ask for a query and it opens as a code document that keeps every version.

  • Switch models mid-chat

    Start on a cheaper model; if the answer isn't good enough, switch models in the same chat. The next model sees the whole conversation, so you don't paste anything twice.

Tips

  • Give the CREATE TABLE statements and a few sample rows.

  • Name the database and version.

  • Ask it to explain the query line by line before you run it.

  • For slow queries, share the query plan and ask about indexes.

Bar chart: Prompts passed in our test runs, sql. GPT-6 Luna: 5 of 5; GLM 5.3 Flash: 5 of 5; DeepSeek V4.1 Flash: 5 of 5; Claude Haiku 5.5: 5 of 5; GLM 5.3: 5 of 5; Gemini 3.8 Flash: 5 of 5; Claude Haiku 4.5: 5 of 5; DeepSeek V4 Pro: 5 of 5; Mistral Large 4: 5 of 5; Grok 4.7: 5 of 5; GPT-6.1 Sol: 5 of 5; GPT-6 Sol: 5 of 5; Kimi K3: 5 of 5; Claude Sonnet 5: 5 of 5; Claude Sonnet 5.5: 5 of 5; Gemini 3.1 Pro (preview): 5 of 5; Gemini 4 Argon: 5 of 5; Claude Opus 5.5: 5 of 5; GPT-6 Astra: 5 of 5; Claude Fable 5.1: 5 of 5.
Our test runs of September 27, 28, 29 and October 2, 7, 8, 9, 15, 2026: the same prompts for every model, each reply checked the same way.

Questions

What is the best AI for SQL?

In our test runs on October 15, 2026, 20 of the 20 models passed 5 of 5 SQL prompts, so these prompts don't name one best model. For best value, GLM 5.3 (5 of 5). For everyday, GPT-6 Luna (5 of 5). Every prompt and reply is published, so you can check them, and the picks follow fixed rules.

How did you test the models for SQL?

We sent the same SQL prompts to every model through llmwise's own pipeline and checked each reply the same way. The prompts, the replies, how each was scored and the grader are all published on the methods page.

Can I try these models for SQL for free?

Yes, to try: Free is a one-time trial of 5 messages on Claude Haiku 5.5.

Can it connect to my database?

Not by itself. llmwise doesn't connect to your database. Paste the schema instead; on Pro and higher plans you can connect an MCP server that gives the model database tools, if you run one.

Which SQL dialects does it write?

Any the model knows well: PostgreSQL, MySQL, SQLite, SQL Server, BigQuery and so on. Name yours and its version in the first message.

Claude, GPT, Gemini, DeepSeek, Grok, Kimi, GLM, and Mistral, in one chat.

See what a message costs before you send it. Free is 5 messages to try; sign in with an email link, no password or card.