Search⌘ K

Writing Clear Prompts

Learn how to write clear prompts for SQL

Step 1: Start with a curious question

You already know how to look inside a table. Now let’s focus on the questions that make those queries meaningful. Consider a business dataset, such as employee information. What are you genuinely curious about?

Maybe:

Who gets paid the most?

or

Which departments have the highest average salary?

Before we dive into SQL, let’s ensure these questions are precise. The AI can only write good SQL if you give it a focused question.

Step 2: Compare vague vs. clear prompts

Let’s test two ways of asking the same thing. Ask the AI both ways and compare its responses.

Vague prompt: Write a SQL query for: Tell me something about employee salaries.

Then again:

Clear prompt: Write a SQL query for: Show me each employee’s name and salary, ordered from highest to lowest.

Powered by AI
5 Prompts Remaining
Prompt AI WidgetOur tool is designed to help you to understand concepts and ask any follow up questions. Ask a question to get started.

Execute both versions and compare the results. Which output matches your intended behavior more closely and why?

MySQL
-- Paste your SQL query here:

Step 3: Guided reflection

Good data questions clearly specify three things:

  • What do you want to see? The columns or fields you want returned.

  • Where does the data live? The table or tables to query.

  • How do you want it filtered or sorted? Any conditions, constraints, or ordering rules.

When your prompt includes all three components, the AI can generate accurate SQL with minimal correction.

Try this thought experiment:

Show me _____ of _____ where _____.

Can you fill that in for your own table? That simple pattern turns plain curiosity into query logic.

Step 4: Refine and run

Let’s practice improvement.

Ask AI:

Show me all employees.

Then, refine your own question by adding detail:

Show me first name, last name, and department of employees in the Engineering department.

Compare both SQL versions side by side.

Powered by AI
5 Prompts Remaining
Prompt AI WidgetOur tool is designed to help you to understand concepts and ask any follow up questions. Ask a question to get started.

 Run the result:

MySQL
-- Paste your SQL query here:

Ask yourself:

  • How did the structure of my question change the columns or rows?

  • Did adding a condition (WHERE department = 'Engineering') make the answer more useful?

Step 5: Your turn to tweak

Now you’ll write one yourself, without AI. Take the correct code given to you below:

Task: Change it to show employees in the Marketing department instead.

MySQL
SELECT first_name, last_name, department
FROM employees
WHERE department = 'Engineering';

Run it and see if you get different rows. That’s your first act of precision through wording, a transferable habit.

Quick recap

Good Prompt Feature

Why It Matters

Example Phrase

Specific columns

Guides AI to pick the right fields

name and salary

Named table

Points SQL to the right data source

from employees

Condition or order

Adds focus

where department = 'Engineering'

One question per prompt

Keeps results interpretable

Top 3 earners. Show top earners, departments, and hires.

Practice prompts

Try these in the AI Prompt Widget:

  1. Show me the names and salaries of all employees.

  2. Show me only the employees who work in Sales.

  3. List all employee names and departments, sorted alphabetically.

Then, open the SQL widget and manually tweak one query, change a column, or adjust the table name.

Reflect before moving on

  • How does changing a single word in your question change the SQL?

  • Which of your prompts gave you the clearest result?

  • How might you ask the same question in two slightly different ways to test understanding?

You’ve completed this lesson. You can now ask precise, answerable data questions, guide AI to produce accurate SQL, and read and adjust its output with intention.