SQL Interview Coaching With Worked Solutions
Solves a SQL challenge as a teaching session, showing the thought process, solution, and common traps.
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
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
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
Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.
Techniques in this prompt
Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.
Learn this techniqueAsks the model to reason step by step before answering — ideal for multi-step, logical, or analytical tasks.
Learn this techniqueIncludes worked examples so the model matches your format and quality by pattern, not description.
Learn this techniqueRecommended models
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
Translate Business Questions Into SQL
Turns a plain-English stakeholder question into a correct, well-commented SQL query against a known schema.
Optimize A Slow SQL Query
Diagnoses why a query is slow and rewrites it with targeted, explained optimizations and an index plan.
Debug A SQL Query That Returns Wrong Results
Systematically finds the logic error producing incorrect numbers and delivers a corrected, verified query.
Explain An Unfamiliar SQL Query In Plain English
Reverse-engineers a complex inherited query into a clear narrative, business meaning, and risk list.