EN
My account

Your privacy, your call. No advertising cookies. May we count your visit in aggregate (Cloudflare, no cookies) and remember where you came from? If you reject, we won’t measure your visit. · Cookies · Privacy

Privacy settings

Choose what we measure and what we keep in this browser. We never sell or share your data.

Essential

Remember your theme, language, saved items and this choice. Without them the site cannot work the way you ask.

Always on

Keeps the source of your first and latest visit for 90 days (utm parameters and referring site). It only leaves your browser if you subscribe to the newsletter.

Cloudflare Web Analytics counts visits in aggregate: page, referring site, country, browser and load times. No cookies, no identifiers and no profiling; nothing is stored in your browser. It only loads if you accept it. If you reject it or switch it off, it does not load (or stops loading from the next page) and we do not count your Telegram clicks either.

Cookies · Privacy

Work · Professional prompt

SQL query from a question

Professional structure: role, context, objective, details, steps, format, criteria and self-check. Designed for better results, not guaranteed ones: always review the answer.

Never use real personal data. If you need to, run it through the data cleaner.

Fill in the blanks
## Role
Act as a data analyst who is an SQL expert.

## Context
I need to pull a figure from the database and I am not fluent in SQL.

## Objective
Get a correct query for my database engine, with an explanation.

## Details (fill in what is in square brackets)
- [engine: PostgreSQL, MySQL, SQL Server, BigQuery…]
- [relevant tables and columns]
- [business question]

## Step-by-step instructions
1. Restate the question in terms of tables and columns.
2. Write the query with clear aliases.
3. Explain each part: joins, filters and grouping.
4. Propose a check to validate the result.

## Output format
Query in a code block, explanation and a checking query.

## Quality criteria
- It uses the syntax of the stated engine.
- It avoids SELECT * in the final result.
- It handles nulls and duplicates in joins.

## Self-check
Before answering, check every quality criterion. If information is missing, ask me instead of making it up, and at the end state what you have assumed.

The link opens the empty template: what you type is not included.

Objective

Get a correct query for my database engine, with an explanation.

When to use it

This prompt is brilliant when you have a clear business requirement but struggle with the specific syntax required by your database engine. It is most useful for ad-hoc reporting, quick data exploration, or debugging legacy queries. However, avoid using this for complex database architecture changes or sensitive write operations, as an AI might misinterpret table relationships. Always verify the logic against your schema manually; while it provides a solid foundation, you remain responsible for the data's accuracy and integrity.

Worked example: input (fictional data)

Engine: PostgreSQL Tables and columns: - Table: 'subscriptions' (columns: sub_id, customer_id, plan_cost, start_date) - Table: 'customers' (columns: customer_id, full_name, email, region) Business question: I need a list of the top 5 customers from the 'North' region who have spent the most on subscriptions since January 1st, 2024. Please show their full name and the total amount spent, formatted in GBP.

Worked example: full response

Here is the SQL query tailored for PostgreSQL to find your top spending customers in the North region: SELECT c.full_name, SUM(s.plan_cost) AS total_spend FROM customers c JOIN subscriptions s ON c.customer_id = s.customer_id WHERE c.region = 'North' AND s.start_date >= '2024-01-01' GROUP BY c.customer_id, c.full_name ORDER BY total_spend DESC LIMIT 5; Explanation of the query: - JOIN: Combines the customers and subscriptions tables using the customer_id field. - WHERE: Filters for customers specifically in the North region and restricts the date range to the current year. - SUM: Calculates the total plan_cost for each customer grouping. - GROUP BY: Organises the results by customer to ensure accurate aggregation. - ORDER BY and LIMIT: Ranks the spending from highest to lowest and restricts the list to the top 5. To validate these results, you can run this check: SELECT SUM(plan_cost) FROM subscriptions WHERE start_date >= '2024-01-01'; Compare this total against the sum of the results returned by the main query to ensure no data is missing or duplicated. If the figures differ significantly, check if any customers have multiple subscriptions that might be causing unexpected multiplication during the join process.

Variants

Quick and concise

Provide only the SQL query and a brief one-sentence explanation for each major clause. Skip the validation step and detailed breakdown. Focus on getting a clean, working query as quickly as possible for experienced users who just need the syntax drafted.

For data beginners

Act as a patient tutor. Please write the query but explain each step in plain English, avoiding overly technical jargon. Include a breakdown of why we choose specific joins and how the aggregate functions work. Help me understand the 'why' behind the code, not just the code itself.

With schema context

Before writing the query, first analyse the table relationships provided. Identify potential issues, such as missing foreign keys or ambiguous column names. Then, write the query and include a comment block at the top detailing your assumptions about the data structure to ensure better results.

Common mistakes

Related guide

General and assistant-specific tips

Tips by assistant

  • ChatGPT: you can attach the file (Excel, CSV or PDF) and ask it to analyse it; ask it to show the calculations it made.

Getting the most out of it

  • Paste the prompt as is and only replace what is in [brackets].
  • If the answer does not fit, do not start over: ask for “shorter”, “more formal” or “as a table”.
  • Always review the result before using it: AI can get facts, dates or names wrong.

Before you paste it: quick checklist

  • Remove client names, amounts and internal data before pasting.
  • Say who the text is for and which tone you want.
  • Ask for a specific length: “120 words max” or “three bullet points”.
  • Read the result aloud and fix anything you wouldn’t say yourself.

How to adapt it to your assistant

The template works the same in ChatGPT, Gemini, Copilot or Claude because it only uses plain language. If your assistant supports fixed instructions (custom instructions, Gems or projects), you can store your preferred tone and format there and paste only the variable part. On a free plan, split long requests into two or three shorter messages.

See all Work prompts

More professional prompts

← All prompts

Found this prompt useful? A new one every Tuesday

Every Tuesday, 5 minutes: AI news with sources, a tool with its prompt and a guide. Free, with one-click unsubscribe. What is inside and a sample issue