wowprompt

SQL query writer from a plain question and table schema

Turns a business question into a working SQL query for your database, with an explanation and a check of edge cases. Use it when you know the question but not the joins, grouping or date logic.

A formatted SQL query, a step-by-step explanation of each clause, a sample output table and a list of assumptions
The output this prompt produced, unedited.

The prompt

Goal

Write one correct, readable SQL query that answers the question below on the schema provided.

Inputs

  • Database: [MySQL, PostgreSQL, SQL Server, SQLite, BigQuery]
  • Question: [e.g. top 10 customers by revenue in the last 90 days]
  • Schema: [paste table names with columns and types]
  • Relationships: [e.g. orders.customer_id links to customers.id]
  • Notes on data: [e.g. cancelled orders have status 'cancelled']

Output format

  1. The query, formatted with one clause per line and keywords in capitals.
  2. Explanation: a numbered list that walks through each clause in the order the database runs it.
  3. Sample output: a small table showing the column names and two or three made-up rows labelled as illustrative.
  4. Assumptions: any decision made where the question was unclear.
  5. Performance note: indexes that would help if the tables are large.

Check before answering

  • Every table and column used exists in the pasted schema.
  • The query uses syntax valid for the stated database, including date functions.
  • Joins use the stated relationships and the right join type; a LEFT JOIN is used where missing rows must still appear.
  • Aggregates have a matching GROUP BY.
  • Date ranges are inclusive or exclusive on purpose, and the choice is stated.
  • NULL values and duplicates are handled.
  • No SELECT star in the final query.
  • The query only reads data. Never write UPDATE, DELETE or DROP unless explicitly asked.
sql query generatortext to sqlsql for beginnersmysql querypostgresql query

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity