Home › Blog › SQL Mock Interview With AI: 12 Practice Questions, a 45-Minute Script and a Rubric (2026)

SQL Mock Interview With AI: 12 Practice Questions, a 45-Minute Script and a Rubric (2026)

To run a realistic SQL mock interview with AI, have a chatbot play the interviewer: it gives you a schema and a business question, you write the query in a real SQL editor against sample data while talking through your approach, then you paste the query and its output back for follow-up questions and a review. The AI is good at asking, probing edge cases and critiquing your reasoning.

To run a realistic SQL mock interview with AI, have a chatbot play the interviewer: it gives you a schema and a business question, you write the query in a real SQL editor against sample data while talking through your approach, then you paste the query and its output back for follow-up questions and a review. The AI is good at asking, probing edge cases and critiquing your reasoning. It has no view of your editor and doesn't run your query, so the typing, running and debugging happen in a database you control, against a timer.

Below: a practice schema with awkward rows, 12 questions by pattern, a 45-minute script with prompts, a worked example and a rubric. Full written answers are in our SQL interview questions guide.

What a SQL interview round actually tests

SQL shows up in four formats, and each needs a different kind of rehearsal:

FormatWhat happensHow to mock it
Live SQL roundYou write queries in a shared editor while the interviewer asks whyAn AI interviewer by chat or voice; you type in your own editor, timer running
Online SQL assessmentTimed questions, auto-graded against hidden test dataTimed solo drills; the real test is taken alone, with no outside help
Concept questions“What's the difference between WHERE and HAVING?” with no editorRapid-fire answers out loud, under a minute each
Take-home or caseA dataset, a business question and a short write-upRehearse explaining the result, not only the query

Employers rarely publish their SQL format. Amazon does: its hiring pages, as summarized on our data science interview rounds page (checked November 17, 2026), describe an online assessment for business intelligence engineers that includes a SQL challenge. Ask your recruiter which format and dialect your round uses. In every format, interviewers listen for whether you ask what a row represents, whether your query survives NULLs, duplicates and ties, and whether you can explain the result.

Set up a practice database with awkward rows

  1. Pick one schema for the week. An online store works: users(user_id, signup_date, country), orders(order_id, user_id, order_date, status), order_items(order_id, product_id, quantity, unit_price), products(product_id, category), plus employees(employee_id, department_id, salary) for ranking questions.
  2. Have a chatbot write the seed script with traps built in (prompt below). SQL questions are decided by edge cases, so your data needs them.
  3. Load it into a local database such as SQLite or PostgreSQL and run every statement. AI-written seed scripts often mix dialects, so test before you trust them.
  4. Time every question: 15 minutes for a medium one. Anything you can't finish goes on tomorrow's list.

Write [SQLite / PostgreSQL / MySQL] CREATE TABLE and INSERT statements for these tables: [paste the five tables above]. About 15 users and 40 orders over three months. Include these traps: two users with no orders, three NULL countries, a cancelled order, two employees tied on salary in one department, a one-person department, and a user who ordered three days in a row. List the traps separately at the end.

Why it works: the obvious query is wrong on this data, which is exactly what an interviewer's follow-up is designed to expose.

12 SQL questions to rehearse, grouped by pattern

PatternQuestionWhat the interviewer listens for
Missing rowsUsers who have never placed an order.LEFT JOIN with IS NULL, or NOT EXISTS; knows NOT IN returns nothing if the subquery has a NULL
Filter timingCategories with more than 1,000 in revenue last month.WHERE filters rows before grouping; HAVING filters groups after
NULL countingUsers with a country on file, and users in total.COUNT(*) counts rows; COUNT(country) skips NULLs
Join fan-outTotal revenue per user, from orders and order_items.Joining one-to-many before summing can double-count; aggregate at the right grain first
Ranking with tiesSecond-highest salary in each department.DENSE_RANK versus RANK versus ROW_NUMBER (worked below)
Top N per groupThree best-selling products per category.A window function in a CTE, then a filter on the rank
Period over periodMonth-over-month revenue change.LAG over a monthly aggregate; the first month's NULL
Running totalsCumulative revenue by day.SUM with an OVER (ORDER BY day) clause; the default frame includes rows tied on the same day
DeduplicationKeep each user's latest address row.ROW_NUMBER by user, newest first, keep row 1
Gaps and islandsUsers who ordered on three or more consecutive days.Remove same-day duplicates, then group streaks by date minus a ROW_NUMBER
Conditional aggregationShare of orders cancelled, per country.SUM of a CASE divided by a count; integer division truncates in some dialects
PerformanceThis query is slow on 500 million rows.Reads the execution plan; indexes join and filter columns; doesn't wrap indexed columns in functions

Also prepare one-sentence answers to concept questions: the logical processing order (FROM and JOIN, WHERE, GROUP BY, HAVING, SELECT, DISTINCT, ORDER BY, LIMIT), UNION versus UNION ALL, a CTE versus a subquery, and what an index costs on writes. Between mocks, the LeetCode SQL 50 study plan checks whether your queries are right; the mock is where you practice explaining them.

A 45-minute SQL mock interview script

MinutesPhaseWhat you doWhat the AI interviewer does
0–3Warm-upOne minute on where you've used SQLAsks about your latest data project
3–8Clarifying questionsAsk what a row means, which dates count, how to treat NULLsAnswers only what you ask
8–22Question 1: joinsState your plan, write and run the query, read rows aloudThen changes one requirement
22–37Question 2: window functionSame loop, then adaptAsks about ties, empty groups or speed
37–42ConceptsFive answers, under a minute eachNotes which answers wandered
42–45FeedbackPaste final queries and outputsScores against the rubric below

Prompt 1: the interviewer

You are interviewing me for a [job title] role that uses SQL every day. Use this schema: [paste your CREATE TABLE statements]. Ask me two medium SQL questions, one on joins and aggregation and one that needs a window function. Ask one question at a time. Answer my clarifying questions briefly and realistically, but don't volunteer requirements. When I paste a query and its output, don't fix it: ask one follow-up that changes a requirement or probes an edge case (ties, NULLs, duplicates, empty groups). Save all feedback until I type 'feedback'.

Why it works: it stops the AI from solving the problem for you, and the follow-up rule forces the second half of the question, which is where most SQL mistakes surface.

Prompt 2: the review

Feedback. My final queries and outputs: [paste]. Review them as a strict SQL interviewer: (1) Is each one right for NULLs, ties and users with no orders? If not, show a specific row that breaks it. (2) Describe, don't write, a simpler version. (3) What would you ask about performance at hundreds of millions of rows? (4) Score my clarifying questions, approach, correctness and explanation from 1 to 5, with one sentence of evidence each.

Why it works: asking for a breaking row turns a vague “looks good” into something you can run and check yourself. To talk instead of type, see our ChatGPT voice mode guide; keep your editor open either way.

Worked example: one question, three follow-ups

The question: return the second-highest salary in each department, from the employees table.

A common first attempt: SELECT department_id, MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees) GROUP BY department_id; It compares salaries with the company-wide maximum, so outside the department holding the top salary it returns each department's highest salary, not its second.

A version that answers the question: WITH ranked AS (SELECT department_id, salary, DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rnk FROM employees) SELECT DISTINCT department_id, salary FROM ranked WHERE rnk = 2;

Follow-up 1: “Two people share the top salary. What do you return?”

With DENSE_RANK, both top earners get rank 1 and the next distinct salary gets rank 2, which is usually what “second-highest” means. RANK jumps to 3 after the tie, so rnk = 2 returns nothing for that department; ROW_NUMBER returns the second top earner, whose salary equals the highest. Say which interpretation you're using before typing.

Follow-up 2: “A department has only one employee. What should it show?”

The query drops it. To list every department, with NULL where there's no second salary, keep the CTE and start from the departments table: SELECT d.department_id, r.salary FROM departments d LEFT JOIN (SELECT DISTINCT department_id, salary FROM ranked WHERE rnk = 2) r ON r.department_id = d.department_id;

Follow-up 3: “The table has 300 million rows. Is this fine?”

Stay practical: an index on (department_id, salary) may help the window function's sort, depending on the database; read the execution plan rather than guessing; and if the result is needed daily, compute it once into a summary table. All three follow-ups were about meaning, not syntax, so say your interpretation out loud before you type.

Score yourself with a SQL rubric

CriterionStrongWeak
Clarifying questionsAsks about NULLs, cancelled orders and ties firstStarts typing straight away
ApproachStates the plan: grain, joins, filters, outputTrial and error
CorrectnessRight on every trap; checks row counts after joinsRight on the happy path only
ReadabilityNamed CTEs, consistent aliasesOne nested block nobody could read aloud
TestingChecks a total against a simpler queryAssumes the output is right
Explaining the resultSays what the numbers mean for the questionReads column names aloud
Handling the changeAdapts without starting overRebuilds from scratch or freezes

Score each row from 1 to 5 after every session. If the same row is weak twice in a row, drill that, not another random question.

A 10-day plan, and what an AI mock can't do

The limits of the AI half:

If your SQL round is part of an analyst loop, our data analyst mock interview guide covers the case and stakeholder rounds, and data analyst interview questions has written answers.

Where CoPilot Interview fits

CoPilot Interview is an AI interview assistant whose AI mock interview builds questions from your résumé and the job description, reads them aloud and scores each spoken answer out of 10. For a SQL role, use it for the spoken half: explaining your approach, concept questions and the behavioral questions in every data loop, with your own editor open for the queries. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. The free practice demo scores typed answers to 145 questions in 10 tracks, free with no signup. CoPilot Interview comes as a desktop app for Windows 10 and 11 and macOS 12 or later, a free iPhone and iPad companion on the App Store (iOS 16 or later) and an Android companion in beta. Paid plans are Standard at $24.99 a month and Pro at $39.99 a month.

In live interviews, follow your employer's rules. Online SQL assessments, proctored tests, AI-led rounds and take-homes with stated rules forbid outside help, so prepare beforehand and take them on your own.

Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.

Frequently asked questions

Can ChatGPT give me a SQL mock interview?

Yes. Paste a schema, ask for one question at a time and tell it not to fix your queries. Run each query in your own database, then paste it and its output back for follow-ups.

How long should a SQL mock interview be?

About 45 minutes: two medium questions with follow-ups, a few concept questions and a review. Online assessments have their own time limits, so check your invitation.

What SQL topics come up most in interviews?

Joins and missing rows, GROUP BY with HAVING, NULL handling, window functions, deduplication, date logic and why a query is slow.

Which SQL dialect should I practice in?

The one in the job description or named by your recruiter. Otherwise standard SQL in PostgreSQL or SQLite is a safe default; date and string functions differ most between dialects.

Can I use AI during a SQL assessment?

Not unless the instructions say so; online assessments generally forbid outside help. Practice with AI beforehand and follow your employer's rules on the day.

Rehearse it out loud before the real one

The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.

Start a mock interview