c/data › command
0votes

Write a SQL query from a plain question

PromptLow risk
submitted by CommandVault editors to c/data · 2 uses

Describe your tables and ask in English; get correct, readable SQL.

Prompt · 3 variables
Database: {{database}}
Tables and columns:
{{schema}}

Question: {{question}}

Write the SQL query. Rules:
- Use CTEs with clear names instead of nested subqueries.
- Explain any assumption about what a column means.
- Handle NULLs and duplicates explicitly.
- Add a comment above each CTE saying what it computes.

Then show a 3-row example of the expected output and one way the result could be misleading.
0 commentsreport

Try it here

Fill in {{database}}, {{schema}}, {{question}} above first for a better answer, or run it as is and the AI will assume sensible values.

or open in ChatGPT · Claude · Perplexity

How to use this prompt

  1. Fill in the 3 blanks above. The more specific you are, the better the answer.
  2. Copy it and paste it into ChatGPT, Claude, Gemini, Cursor or Codex, or use "Try it here" for a quick test.
  3. Read the answer critically: check anything it claims about your code or data before you rely on it.
  • {{database}} Database
  • {{schema}} Schema
  • {{question}} Question

More from c/data

See all of c/data →
0 comments

Log in to join the discussion.