Back to Knowledge Hub
Tutorials

Natural Language SQL: Ask Your Data Questions in Plain English

8 min read·Tags: natural-language-sql, nl2sql, text-to-sql, ai-sql, business-analytics, data-exploration, duckdb

Natural Language SQL: Ask Your Data Questions in Plain English

Most business questions get answered late — not because the data doesn't exist, but because the person with the question can't write SQL and the person who can write SQL is already backlogged three sprints deep. Natural language SQL is the attempt to close that gap, and in 2026 it's genuinely useful — with honest limits worth understanding before you rely on it.

What Is Natural Language SQL?

Natural language SQL (also called NL2SQL or text-to-SQL) is the process of converting a plain-English question into a SQL query that a database can execute. You type "What were our top 5 products by revenue last quarter?" and the system generates the SQL, runs it, and returns the result — no SQL knowledge required.

The underlying technology is a large language model that has been trained to understand database schemas and translate natural language intent into syntactically correct SQL. The model needs to know your schema — table names, column names, relationships — to generate useful queries. Without that context, it generates plausible-looking SQL that references tables that don't exist.

The terms text to sql, ai sql query, and nl2sql all describe the same core idea with slightly different emphases. NL2SQL is the research term; "text to SQL" is more common in commercial tooling; "natural language queries" is what ends up in marketing copy.


How It Works: Two Real Examples

Example 1: Revenue by Region

Plain English question:

"Show me total revenue by region for Q4 2024, sorted from highest to lowest."

AI-generated SQL:

-- Generated SQL (DuckDB dialect)
SELECT
    region,
    SUM(revenue)  AS total_revenue
FROM orders
WHERE order_date >= '2024-10-01'
  AND order_date <  '2025-01-01'
GROUP BY region
ORDER BY total_revenue DESC;

Result:

regiontotal_revenue
EMEA4,821,340
North America4,203,890
APAC2,109,450
LATAM987,210

This is the straightforward case: a clean aggregation with a date filter and sort. The AI maps "Q4 2024" to the correct date range, understands "total revenue" means SUM(revenue), and applies the ORDER BY DESC the question implies. For queries like this — one table, clear intent, standard aggregation — NL2SQL is reliable.


Example 2: Month-over-Month Growth Rate

Plain English question:

"What's the month-over-month growth rate in new customer sign-ups for 2024?"

AI-generated SQL:

-- Generated SQL (DuckDB dialect) — uses window functions for MoM calculation
WITH monthly_signups AS (
    SELECT
        strftime(created_at, '%Y-%m') AS month,
        COUNT(*)                       AS new_customers
    FROM customers
    WHERE created_at >= '2024-01-01'
      AND created_at <  '2025-01-01'
    GROUP BY month
),
growth AS (
    SELECT
        month,
        new_customers,
        LAG(new_customers) OVER (ORDER BY month) AS prev_month,
        ROUND(
            100.0 * (new_customers - LAG(new_customers) OVER (ORDER BY month))
            / NULLIF(LAG(new_customers) OVER (ORDER BY month), 0),
            1
        ) AS mom_growth_pct
    FROM monthly_signups
)
SELECT month, new_customers, prev_month, mom_growth_pct
FROM growth
ORDER BY month;

Result:

monthnew_customersprev_monthmom_growth_pct
2024-011,240NULLNULL
2024-021,3801,240+11.3%
2024-031,5201,380+10.1%
2024-041,1901,520-21.7%

This is more complex — a window function with LAG(), a CTE, and a null-safe division. The AI gets it right because the pattern (MoM comparison) is common in training data. Notice the NULLIF(..., 0) to avoid division by zero — a detail a junior analyst might miss. When NL2SQL works at this level, it's genuinely useful.


NL2SQL Tools and Approaches: A Comparison

The NL2SQL landscape includes standalone tools, embedded features in BI platforms, and API-first approaches:

Tool / ApproachHow It WorksBest ForAccuracy on Complex JoinsPrice
Harbinger ExplorerDuckDB WASM + AI agent chat; schema-aware generationBrowser-based data exploration, ad-hoc analysisGood for single-table and simple joinsFrom €19/mo
ChatGPT / Claude (manual)Paste schema + question into LLM chatOne-off queries when you have time to reviewVariable — depends on schema claritySubscription or API cost
Defog / Wren AIOpen-source NL2SQL engines with schema metadataSelf-hosted data teams wanting full controlGood with proper metadata setupFree (OSS) + cloud tiers
Databricks GenieNatural language queries on Databricks LakehousesEnterprise teams already on DatabricksStrong (purpose-built for the platform)Included in Databricks pricing
Tableau Pulse / Ask DataNL2SQL within Tableau's semantic layerBusiness users on existing Tableau dashboardsLimited to Tableau data sourcesIncluded in Tableau licenses
Mode AINL queries on Mode datasetsAnalysts on Mode platformModerateIncluded in Mode plans

Last verified: March 2026

The accuracy gap between "simple aggregation" and "multi-table join with business logic" is significant across all these tools. None of them are reliable for complex analytical queries without human review. The tools that work best in practice are the ones that combine NL2SQL with easy query inspection — so the user can see and verify the SQL before trusting the result.


When Natural Language SQL Fails

Honest inventory of where it breaks down:

Ambiguous column names. If your schema has a value column in six different tables, the model guesses which one you mean. It usually guesses wrong in surprising ways.

Complex multi-table joins with non-obvious keys. "Show me orders with their customer tier and the product category" requires knowing that orders.customer_id joins to customers.id, that customers.tier_id joins to tiers.id, and so on. Without explicit relationship metadata, the AI invents join conditions that look plausible but return wrong results.

Business logic that isn't in the schema. "Active customers" means different things at different companies — 30-day activity? Non-churned status? A flag? The model doesn't know your business definition. If it's not in the schema or a description field, the SQL will reflect a generic interpretation.

Time calculations that require domain context. "Last quarter" is usually fine. "Year-to-date adjusted for our fiscal year that starts April 1" requires business context the model doesn't have unless you explicitly provide it.

Queries that sound simple but require subqueries or statistical functions. "What's the median order value by customer segment?" sounds simple. The SQL requires a window function or a specialized median function — and the correct syntax varies by database. Model accuracy drops here.

Stale or incorrect schema context. If the model's schema context is outdated and a column was renamed last month, the generated SQL will fail. Schema freshness is a system design problem, not just a model problem.


Honest Trade-offs

DimensionWhat You GainWhat You Give Up
Speed for simple queriesInstant SQL without writing itReviewing the SQL to check it's correct
AccessibilityBusiness users can self-serveRisk of wrong results being trusted without review
Iteration speedFast exploration and follow-up questionsControl over query structure and optimization
Complex joinsAttempt at the queryAccuracy — multi-table joins need human review
DiscoverabilityNatural entry point for unfamiliar schemasYou still need to know what questions to ask

The most important trade-off: NL2SQL reduces the barrier to generating a query, not the barrier to trusting it. The critical skill shifts from "can I write this SQL?" to "can I tell if this SQL is correct?" — which is actually harder for non-technical users, not easier.

The tools that handle this well add query transparency: show the user the generated SQL, explain what it does, and make it easy to modify or rerun. The tools that hide the SQL behind a clean UI create a false sense of reliability.


Where It Genuinely Works Well

Despite the limitations, NL2SQL is genuinely useful in specific contexts:

  • Exploratory analysis on familiar data — when a business analyst knows their own data model and just needs SQL generated for standard aggregations, NL2SQL saves significant time
  • Getting unstuck on syntax — "how do I write a PIVOT in DuckDB?" is a legitimate use of an AI chat interface even if you verify the output
  • First-pass analysis — generating a SQL draft that an analyst then edits and validates is often faster than writing from scratch
  • Democratizing access to structured data — for truly simple questions against clean schemas, non-technical users can get real answers without waiting for an analyst

Harbinger Explorer takes this approach: a built-in AI agent chat interface that generates DuckDB SQL from natural language questions, shows you the query it built, and lets you run it against your connected data sources directly in the browser. The transparency — seeing and being able to modify the generated SQL — is what makes it trustworthy for real analysis rather than a novelty. You can try it on your own data with a 7-day free trial.


Getting the Best Results from NL2SQL

A few practical tips that consistently improve output quality:

  1. Be specific about aggregation. "Show me revenue" is ambiguous. "Show me total revenue (sum of the revenue column in the orders table) grouped by month" gives the model what it needs.

  2. Name your tables in the question. "How many rows are in transactions where status = 'completed'?" is more reliable than "How many completed transactions do we have?"

  3. Check the SQL before trusting the number. Especially for anything going into a report or decision. This should be a habit, not an exception.

  4. Iterate conversationally. "That's close, but filter to only include paid plans" usually works better than trying to write the complete question in one shot.


Next Steps

Natural language SQL lowers the barrier to data exploration — with the caveat that result accuracy requires human verification for anything complex. To go deeper:

The field is moving fast. Models are improving at multi-table joins and business logic inference. But the fundamental constraint — "the model doesn't know your business definitions" — is a data governance problem, not just a model problem. The best NL2SQL implementations pair the AI with well-documented schemas and clear business metadata.


Continue Reading


[VERIFY] Databricks Genie feature availability — confirm GA status vs. beta as of March 2026
[VERIFY] Defog / Wren AI current feature set and open-source status
[PRICING-CHECK] All tool pricing tiers — last verified March 2026


Continue Reading

Try Harbinger Explorer for free

Connect any API, upload files, and explore with AI — all in your browser. No credit card required.

Start Free Trial