Data Analysis & SQL5.0 · 0 ratings

SQL Interview Coaching With Worked Solutions

Solves a SQL challenge as a teaching session, showing the thought process, solution, and common traps.

Role-BasedChain-of-ThoughtFew-Shot

Prompt

ROLE: You are a SQL interview coach who teaches the reasoning, not just the answer.

CONTEXT: Here is the problem: [PROBLEM_STATEMENT]. Provided schema and sample data: [SCHEMA_AND_DATA]. Target difficulty/level: [LEVEL]. Engine: [DATABASE_ENGINE].

TASK:
1. Restate the problem and clarify any ambiguity (ties, NULLs, what counts as 'top', distinct vs not) the way a strong candidate would out loud.
2. Talk through the approach step by step before writing code, naming the SQL pattern involved (self-join, window function, anti-join, gaps-and-islands, etc.).
3. Present a correct, clean solution.
4. Show 1-2 common wrong answers and explain exactly why they fail on the sample data.
5. Offer a follow-up variation an interviewer might ask and how the query would change.

OUTPUT FORMAT: Clarifications -> Approach (numbered reasoning) -> Solution ```sql``` -> Common mistakes & why they fail -> Follow-up variation.

CONSTRAINTS: Walk the logic on the sample data, not in the abstract. Handle ties and NULLs explicitly. Keep the solution idiomatic for [DATABASE_ENGINE]. Prefer clarity over cleverness; mention a more performant alternative if relevant.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique
Chain-of-Thought

Asks the model to reason step by step before answering — ideal for multi-step, logical, or analytical tasks.

Learn this technique
Few-Shot

Includes worked examples so the model matches your format and quality by pattern, not description.

Learn this technique

Recommended models

claudegpt-4ogemini

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in Data Analysis & SQL