genstarters
Task New #sql#data#coding

SQL Query From Plain English

Writes SQL from a natural-language question. Explains the query, flags assumptions about the schema, and warns about performance risks.

The prompt

I'll describe what I want to query. Write the SQL, then explain it.

First, ask me these (unless already given):
- Which SQL dialect? (Postgres, MySQL, SQLite, BigQuery, Snowflake, other)
- The relevant table schemas (columns and types), even if partial.

Then output:

**The query** — formatted, readable, with meaningful CTEs if it helps clarity over inline subqueries.

**What it does** — 2-3 lines explaining the logic in plain English.

**Assumptions I made** — anything about the schema, data cleanliness, or intent that I inferred rather than knew.

**Performance notes** — if this could be slow (full table scan, missing index, cross join, window over large partition), say so and suggest what to add.

Rules:
- Never invent columns. If the schema doesn't have what's needed, ask.
- Prefer explicit JOINs over old-style comma joins.
- Add `LIMIT` to exploration queries. Never to aggregations.
- Use lowercase keywords or match the user's style if they gave an existing query.

## How to use it

Paste this prompt with your question and (ideally) the relevant schema. Example: "Count active users per day for the last 30 days. Schema: users(id, created_at, last_login_at, plan_tier)."

## Why it works

The assumptions section catches the moments where the AI guesses at schema or intent. The performance notes prevent shipping a query that works on 1,000 rows but times out on 10 million.

How to use it

I’ll describe what I want to query. Write the SQL, then explain it.

First, ask me these (unless already given):

  • Which SQL dialect? (Postgres, MySQL, SQLite, BigQuery, Snowflake, other)
  • The relevant table schemas (columns and types), even if partial.

Then output:

The query — formatted, readable, with meaningful CTEs if it helps clarity over inline subqueries.

What it does — 2-3 lines explaining the logic in plain English.

Assumptions I made — anything about the schema, data cleanliness, or intent that I inferred rather than knew.

Performance notes — if this could be slow (full table scan, missing index, cross join, window over large partition), say so and suggest what to add.

Rules:

  • Never invent columns. If the schema doesn’t have what’s needed, ask.
  • Prefer explicit JOINs over old-style comma joins.
  • Add LIMIT to exploration queries. Never to aggregations.
  • Use lowercase keywords or match the user’s style if they gave an existing query.

How to use it

Paste this prompt with your question and (ideally) the relevant schema. Example: “Count active users per day for the last 30 days. Schema: users(id, created_at, last_login_at, plan_tier).”

Why it works

The assumptions section catches the moments where the AI guesses at schema or intent. The performance notes prevent shipping a query that works on 1,000 rows but times out on 10 million.

✦ More like this

Related prompts