Skip to content
trending

Benchmarks

Best AI for SQL: ChatGPT, Gemini or Claude Code?

I tested GPT-6.1 Sol on a tricky SQLite database. It got all three queries right. Here’s how ChatGPT, Gemini and Claude Code compare.

By 3 min read

Update (9 Nov 2026): Claude Fable 5.2 and Mythos 5.2 are out - prices, access and benchmarks are in my Claude Fable 5.2 guide.

👁 118 reads

ChatGPT Plus with GPT-6.1 Sol was the best option for writing SQL queries in my test: it wrote three queries for a tricky database, and all three returned exactly the expected results. If you only write SQL occasionally, free ChatGPT or Gemini should be enough. If you’re working across a whole project with migrations and files, Claude Code on the Claude Pro plan is a better fit.

This is one of the quick answers in the Which AI for what? - 50 answers series. I tested the tools on 8 October 2026.

Three options: free, best overall and for advanced work

My quick test

I built a SQLite shop database with 40 customers and 89 orders, including two traps: a guest order with no customer, which can make the common “NOT IN” pattern return an empty list, and a join that inflates the customer count unless you use DISTINCT. GPT-6.1 Sol, accessed through the API, wrote three queries: a ranking of cities in the third quarter, customers with no orders, and the cancellation rate for each month. I ran them on the database, and all three returned exactly the results in my answer key. The model used NOT EXISTS and COUNT(DISTINCT) on its own. The test cost $0.008. The test prompts were in Polish; the results reflect a Polish-language test, not an English-language one.

Dealat Kinetyra
Replit Core - 12 months
$109 instead of $267 -59%
See the deal →

What to watch out for

  • Always specify the SQL dialect (PostgreSQL, MySQL, SQL Server or SQLite) and provide the table schema. Otherwise, the model has to guess column names and date functions.
  • Don’t paste customer data or database passwords into a chatbot. The schema (CREATE TABLE) and a few fictional rows are enough.
  • Run AI-generated UPDATE and DELETE statements on a copy first, or inside a transaction you can roll back.
  • Check the result against a small sample you can calculate by hand. A query can run successfully and still count the wrong things.

Copy-and-paste SQL prompt

Translation of the original Polish prompt template:

I'm using [PostgreSQL / MySQL / SQL Server / SQLite]. Schema:
[paste CREATE TABLE statements for the relevant tables]
Data notes: [for example, customer_id can be empty, dates are text in YYYY-MM-DD format, status values are 'new', 'paid' or 'cancelled'].
Task: [what you want to calculate, for which period, and under what conditions].
1. Write the query and explain it in two sentences.
2. Point out potential pitfalls: NULL values, duplicate rows after joins, and date boundaries.
3. Add a short validation query I can use to check the result on a small sample.
Google · Your sourcesQuantslant higher in your Google - one clickAdd to preferred sources →

Frequently asked questions

Which AI tools are free for SQL?

Free ChatGPT and Gemini can write typical queries when you provide the table schema and SQL dialect. They have lower message limits than their paid plans.

Does ChatGPT write correct SQL queries?

In my test, GPT-6.1 Sol wrote three out of three correct queries and avoided both traps. You should still check the results against data you understand.

Can AI connect directly to my database?

It can. For example, Claude Code can run queries in a terminal. Give it access only to a copy or a read-only account, never to a production database with full permissions.

Find more quick answers in the Which AI for what? roundup, and see AI tools for coding for coding tools and their prices. If your data is in a spreadsheet, read the article about AI for Google Sheets.

// read next

More on this from QUANTSLANT

Piotr Olszewski

Editor and publisher · Quantslant

I edit and publish Quantslant. AI tools help with research, drafts and translation; choosing topics, running the tests, checking facts and the decision to publish are mine, and so is the responsibility for what appears here.

read nextbenchmarksGemini 4 Argon Prompts: 12 Tested ExamplesTwelve prompts tested in Polish show how Gemini 4 Argon handles long documents, calculations, code, and more - with results and costs.

Most read

  1. 1Best AI Video Generator Apps for Your Phone (2026)
  2. 2Claude Opus 5.5 Motion Graphics: 60s Showreel from One Prompt
  3. 3Wan 2.2 on RTX 4090: timings, VRAM and four test clips
// site map

This page in other languages5

Quantslant in numbers 1,423posts in archive22news from the last 7 days18video models in the observatory
🎬 AI Video Benchmarks: Higgsfield DoP vs OpenAI Sora • Higgsfield vs Runway Gen-3 • AI Video Credit Calculator
× ‹ enlarge ›