Skip to content

SQL screening questions: sample answers and a worked query

The useful distinction is whether the candidate ran, changed or wrote the query, before a technical interviewer judges the code itself.

· 10 min read

A rounded code window representing a practical query-writing exercise.

Use these SQL screening questions to distinguish candidates who run existing reports, modify queries and write or maintain SQL themselves.

Ask what the applicant wrote, changed and checked, not just whether they have “SQL experience”. The sample answers clarify those levels of responsibility, and the worked revenue query gives a technical interviewer sample data, expected results and a practical follow-up test.

How do you ask about SQL experience on an application form?

Before changing the form, ask the hiring manager what the person needs to do:

What will this analyst need to do on their own: run existing reports, change them or write new ones? Which skills will we teach?

A query is an instruction for retrieving information from a database. If the job needs someone to write those instructions, ask for an example:

Tell us about one question you answered using SQL.
What did you write or change yourself, and how did you check the answer?
Keep it under 150 words.
Please leave out confidential data or code.

Tell applicants which settings are acceptable, including university or personal projects when they fit the role. Writing a relevant query does not necessarily require a previous analyst job; paid-work experience should be a requirement only where the vacancy needs it.

Keep the rest of the form proportionate. Use yes-or-no questions for clear factual conditions, and spend the longer answer on information the next interviewer will actually use.

Compare three answers that all count as SQL experience

These sample replies describe three different kinds of SQL experience:

Uses a report someone else wrote: “I ran our weekly customer report and changed the dates. Our analyst wrote it. When an account was missing, I told her.”

Writes a new report: “Sales needed a report of each customer's spending. I wrote it, noticed that some orders were counted twice and fixed the mistake. I checked the new total against the original orders.”

Fixes an existing report: “A senior analyst wrote our daily order report. When the file it used changed, I updated the code and checked the totals.”

The second answer describes writing a new report. The third describes maintaining an existing one, which may be equally relevant to a maintenance-focused role. The first describes using another person's work.

Compare the responsibility with the actual job. Someone maintaining established reports may not need to design new ones immediately. The answers tell you what to investigate; the later technical task tests whether they can do it.

A report that worked first time can be a good example too. Ask how the applicant checked it. You need the method, not a dramatic failure story.

How can a recruiter follow up without being a SQL expert?

For the sales-report answer, ask what prompted the check:

What first made you think some orders were being counted twice?

Then clarify the test if needed:

Which orders did you compare, and how did you check that none had been left out?

Record how they checked the report and where the comparison came from. A second dashboard may repeat the same faulty query, so “the dashboards matched” is not necessarily a useful check. Pass on the method, not a premature “excellent at SQL” rating.

A useful handover could say:

The applicant says they wrote a sales report and fixed a mistake that counted orders twice. Please ask what caused it and check their solution using sample data. We do not need their employer's code or customer information.

A short email or recruiter call may be enough for a few applications. Screened voice interviews are another way to collect these accounts and follow-up answers across a larger group. Check the relevant transcript passage before passing it to the technical interviewer. The product collects the explanation; the technical assessment remains a separate step.

Optional SQL exercise: why did the revenue total change?

The technical interviewer can use this exercise instead of asking for a previous employer's report. The report needs one row per customer, showing their total revenue and contact names. Every genuine order must count once, even when a customer has several contacts.

Start with the explanation. For a coding version, give the applicant the two input tables defined in the PostgreSQL exercise, the output requirement and the permitted tools. Keep the completed query in the interviewer’s guide.

All amounts use the same sample currency, every order ID is unique and each contact row represents a distinct person. This exercise concerns customers with orders; including customers with no orders would be a separate requirement.

Start by asking why adding contacts changed the revenue total. After the applicant proposes a fix, add another genuine order with the same amount as an earlier one. That catches a tempting shortcut: removing repeated amounts rather than counting each order once.

Explain the time, permitted tools and adjustment route before starting. Keep the worked answers and additional order in the interviewer's guide. Accept any solution that counts every genuine order once and retains the required contact information.

Open the exercise: why did adding contacts change the revenue?

Give the applicant the orders. Customer A has two contacts, Alex and Beth. Customer B has one, Casey. These are three distinct people, not duplicate contact entries.

Order Customer Amount
1 A £60
2 A £40
3 B £50

Ask: “A draft report pairs each order with every contact for that customer. Which rows would it produce, and what would happen if we added their amounts? How would you produce the one-row-per-customer report we need instead?”

First answer: the total rises from £150 to £250

The genuine orders total £150. After adding the contacts, the report has five rows: £60, £60, £40, £40 and £50. Customer A has two contacts, so each of A's orders appears twice. Adding those rows gives the incorrect total of £250.

Each order must contribute its amount once, even when several orders have the same value. Ask how the proposed query identifies an order and check both the customer totals and overall total.

Now add Order 4: another genuine £40 order for Customer A. Ask whether the proposed fix still works.

Second answer: equal amounts can belong to different orders

The correct total is now £190: £140 for Customer A and £50 for Customer B. The two £40 orders are both real. A fix that removes one simply because its amount is repeated would lose genuine revenue.

Using SUM(DISTINCT amount) would still return £150 here: £60 + £40 + £50. It removes a genuine £40 order along with repeated values. DISTINCT applies to the amount, not the identity of the order. See PostgreSQL's aggregate-expression documentation.

A solution could total the orders for each customer and collect that customer's contact names separately, then combine those results. The applicant may propose a different report layout, but should explain the change rather than quietly drop the requirement to show contacts.

Technical interviewer notes: how to assess the SQL exercise

The first correct total is £150. After adding another real £40 order, it is £190. A fix that removes all repeated amounts gets the first example right but loses the new order. That is the mistake this exercise is designed to reveal.

Assess three things: can the applicant explain why orders were counted twice, propose a solution that counts every real order once and test that solution against the new example?

Check the proposed output, not only its final total. Before the added order, it should show Customer A, £100, Alex and Beth; and Customer B, £50, Casey. Afterwards, A's revenue becomes £140 and B's stays £50. A design that repeats customer revenue on every contact row needs a different way to calculate the overall total.

Accept different query or report designs that meet the stated need. The applicant should explain how the report looks and how its totals are calculated. The name of the database operation matters less than whether its result meets the stated requirement.

Technical interviewer: sample data and a PostgreSQL solution

This self-contained query uses made-up data and creates no tables. Give the applicant the orders and contacts definitions and ask for one row per customer with total revenue and contact names. Keep the two aggregation steps and completed solution out of their starting brief.

WITH orders (order_id, customer_id, amount) AS (
    VALUES (1, 'A', 60),
           (2, 'A', 40),
           (3, 'B', 50)
),
contacts (contact_id, customer_id, contact_name) AS (
    VALUES (1, 'A', 'Alex'),
           (2, 'A', 'Beth'),
           (3, 'B', 'Casey')
),
revenue AS (
    SELECT customer_id, SUM(amount) AS total_revenue
    FROM orders
    GROUP BY customer_id
),
contact_lists AS (
    SELECT customer_id,
           STRING_AGG(contact_name, ', ' ORDER BY contact_name) AS names
    FROM contacts
    GROUP BY customer_id
)
SELECT r.customer_id, r.total_revenue, c.names
FROM revenue AS r
LEFT JOIN contact_lists AS c
    ON c.customer_id = r.customer_id
ORDER BY r.customer_id;

Expected rows, shown as customer_id | total_revenue | names: A | 100 | Alex, Beth and B | 50 | Casey. Add (4, 'A', 40) to the orders and rerun: A becomes 140, B stays 50, and the overall revenue is 190. The uncorrected order-to-contact join would sum to 330 after that addition; SUM(DISTINCT amount) still gives the wrong 150.

The solution aggregates each one-to-many table before joining, so contacts cannot multiply revenue. The left join also retains a customer’s revenue if that customer has no contact record. Contact names are not treated as unique person IDs.

PostgreSQL documents common table expressions and ordered aggregates. Adapt the syntax for another database and test the interviewer’s copy before use.

Ask the specialist what the applicant actually did: explain the extra rows, preserve the second genuine £40 order and keep the required contact information? Note any help given. That gives you more to discuss than “passed SQL”.

A useful specialist handover could say:

Explained that each order was repeated for every matching contact. Aggregated orders before combining them with contact names and kept the second genuine £40 order. The result met the one-row-per-customer requirement. We did not assess query performance on a large dataset.

Use that wording only for work the applicant actually demonstrated, and record any prompts needed. The application describes past work; this exercise supplies separate evidence of what they did today.

What if applicants already answered the old yes-or-no question?

Ask the affected applicants for the specific example and explain why it helps the review. Their original “yes” answered the form you gave them; it is not evidence that they avoided a harder question.

Apply the same clarification approach to comparable applications, including those already reviewed. Use the replies to decide what to assess next. The new question improves the information available; it does not retrospectively verify anyone's SQL.

State whether editing help or AI assistance is allowed

Put the assistance rule beside the question, not in a policy applicants have to find elsewhere. If you permit editing help, you could say: “You may use tools to improve the wording. The example must describe your own experience and accurately explain what you did.”

Give reviewers the same instructions. The technical exercise may use different rules, provided applicants receive them before starting. If AI is allowed, the applicant still needs to explain and test the query. A solution that loses the second £40 order has not met the requirement.

Check whether the new question improves the next interview

Before adding the question, ask a recruiter and the technical interviewer to read the same sample answers. Can they agree which responsibility is described and what remains to test?

If they disagree, find out why. The hiring manager must decide whether running a saved report is enough for the role. A vague answer about who wrote it needs clarification. Neither problem is solved by making the answer box longer.

Check whether the technical interviewer uses the answer. They should be able to start with the duplicate-order problem rather than ask for the same career summary again. If they cannot, fix the question or handover before asking applicants for more information.