NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

UNJOIN: Enhancing Multi-Table Text-to-SQL Generation via Schema Simplification

Poojah Ganesan, Rajat Aayush Jha, Dan Roth, Vivek GuptaarXiv 2025 · OpenReview

Abstract

Recent advances in large language models (LLMs) have greatly improved Text-to-SQL performance for single-table queries. But, it remains challenging in multi-table databases due to complex schema and relational operations. Existing methods often struggle with retrieving the right tables and columns, generating accurate JOINs and UNIONs, and generalizing across diverse schemas. To address these issues, we introduce UNJOIN, a two-stage framework that decouples the retrieval of schema elements from SQL logic generation. In the first stage, we merge the column names of all tables in the database into a single-table representation by prefixing each column with its table name. This allows the model to focus purely on accurate retrieval without being distracted by the need to write complex SQL logic. In the second stage, the SQL query is generated on this simplified schema and mapped back to the original schema by reconstructing JOINs, UNIONs, and relational logic. Evaluations on SPIDER and BIRD datasets show that UNJOIN matches or exceeds the state-of-the-art baselines. UNJOIN uses only schema information, which does not require data access or fine-tuning, making it scalable and adaptable across databases.

Introduction

While Large Language Models (LLMs) have become remarkably proficient at generating SQL for single-table queries, multi-table databases remain a significant hurdle. In these complex scenarios, a model must simultaneously identify the correct columns across dozens of tables and determine the necessary "plumbing"—the JOIN conditions, foreign key relationships, and UNION operations—to connect them.

The structural complexity of multi-table schemas often "distracts" LLMs, leading to compounding errors. For instance, if a model fails to identify a necessary table, the entire JOIN logic collapses. Existing solutions typically attempt to solve schema linking and query construction in a single step, which struggles to scale as databases grow in complexity. To overcome this, we propose UNJOIN, a novel framework that simplifies complex multi-table Text-to-SQL tasks by "flattening" database schemas into a single virtual table.

The UNJOIN Methodology

The core innovation of UNJOIN is a two-stage process called Schema Simplification, which decouples data retrieval from complex relational logic:

  1. Stage 1: Flattening the Schema. The framework merges all columns from every table in the database into a single, flat "virtual" table. Every column is renamed using a TableName.ColumnName convention to maintain context. The LLM then generates a "simplified" SQL query against this single table, focusing purely on what data is needed (filtering and selection) without the burden of table connectivity.
  2. Stage 2: Query Translation. This simplified query is translated into standard SQL. During this stage, the model reconstructs the necessary JOINs, UNIONs, and relational logic based on the original multi-table schema.
The UNJOIN methodology: Schema conversion to a single virtual table followed by SQL translation back to the multi-table schema.

We evaluated two variants: UNJOIN_SP (Single Prompt) and UNJOIN_MP (Multi-Prompt). Additionally, an edit-distance-based correction mechanism ensures that any minor hallucinations in table or column names are accurately mapped back to the actual database schema.

Key Insights and Results

UNJOIN was tested on two major benchmarks: SPIDER, a cross-domain dataset with complex queries, and BIRD, a large-scale dataset reflecting real-world challenges with larger schemas and noisier data.

LLMs as "Single-Table Natives"

Our research indicates that LLMs are significantly more reliable when processing data as a flat spreadsheet. By removing the need to reason about table relationships initially, the "retrieval" accuracy—finding the right columns—improves dramatically. This decoupling ensures that the "intent" of the query is established before the "implementation" (the JOINs) is attempted, reducing compounding errors.

Performance and Scalability

UNJOIN demonstrated state-of-the-art (SOTA) or near-SOTA performance across several categories:

  • Accuracy Boost: On SPIDER, UNJOIN_SP achieved an Exact Match (EM) score of 76.13%, outperforming strong baselines like DIN-SQL.
  • Generalization: On the difficult BIRD dataset, UNJOIN_MP achieved an EM of 56.35%, significantly surpassing standard few-shot prompting with Llama 3.3 (70B).
  • Scalability: Unlike standard methods that degrade as the number of tables increases, UNJOIN maintains high retrieval accuracy even in complex environments.
Retrieval accuracy comparison: UNJOIN variants maintain high performance as the number of tables increases, unlike standard CoT methods.

Furthermore, in "Open-Book" settings where relevant tables aren't known beforehand, UNJOIN acts as a powerful enhancer, increasing Exact Match scores by 14.9% to 19.5% compared to standard Chain-of-Thought (CoT) prompting.

Limitations and Future Work

While effective, UNJOIN relies heavily on the LLM's instruction-following capabilities. Smaller models (3B-7B parameters) sometimes struggle with the translation step. Additionally, the current framework focuses on structural correctness rather than "cell-level" disambiguation (e.g., distinguishing between different name formats within the data). Future work may extend this simplification logic to hierarchical (JSON) or semi-structured data formats.

Summary updated

BibTeX
@misc{ganesan2025unjoin,
  author = {Poojah Ganesan and Rajat Aayush Jha and Dan Roth and Vivek Gupta},
  title = {{UNJOIN: Enhancing Multi-Table Text-to-SQL Generation via Schema Simplification}},
  year = {2025},
  eprint = {2505.18122},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.18122},
}
Figure