SQL Query Generator: PostgreSQL JOINs from Plain English

Ask a question that spans multiple tables. Chion profiles every foreign key and relationship, generates the correct JOIN type, and validates ON conditions against your schema — before anything touches your database.

How Chion generates JOINs

Foreign keys, constraints, and relationships profiled automatically.

During schema profiling, Chion catalogs every foreign key, unique constraint, and cross-table relationship. When your question references data from multiple tables, the pipeline selects the correct JOIN type (INNER, LEFT, FULL) based on the relationship and your intent.

The SQL contract validates every JOIN condition against actual foreign keys and column types. The two-layer validator (L1 read-only, L2 runtime lint) catches mis-aliased or non-existent columns before execution.

Examples: English → JOIN queries

Multi-table questions with validated ON conditions.

"Products not ordered in 90 days"

LEFT JOIN + IS NULL
SELECT p.product_name
FROM products p
LEFT JOIN orders o
  ON o.product_id = p.id
  AND o.order_date >= CURRENT_DATE - INTERVAL '90 days'
WHERE o.id IS NULL;

"Revenue per employee by department"

Multi-table JOIN + ratio
SELECT d.department_name,
  SUM(r.revenue) / COUNT(DISTINCT e.id) AS rev_per_employee
FROM departments d
JOIN employees e ON e.department_id = d.id
JOIN revenue r ON r.department_id = d.id
GROUP BY d.department_name;

"Customers with orders but no payments"

LEFT JOIN anti-pattern
SELECT c.customer_name
FROM customers c
JOIN orders o ON o.customer_id = c.id
LEFT JOIN payments p ON p.order_id = o.id
WHERE p.id IS NULL;

"Average order value by category and region"

4-table JOIN
SELECT c.category_name, r.region,
  AVG(o.total) AS avg_order_value
FROM orders o
JOIN products p ON p.id = o.product_id
JOIN categories c ON c.id = p.category_id
JOIN customers cu ON cu.id = o.customer_id
JOIN regions r ON r.id = cu.region_id
GROUP BY c.category_name, r.region;

"Customers who bought in both Q1 and Q2"

Self-join
SELECT a.customer_id
FROM orders a
JOIN orders b ON a.customer_id = b.customer_id
WHERE a.order_date BETWEEN '2025-01-01' AND '2025-03-31'
  AND b.order_date BETWEEN '2025-04-01' AND '2025-06-30';

JOIN FAQ

Try multi-table JOINs in plain English

Connect your PostgreSQL database and ask a question that spans multiple tables.