Preparing for a SQL interview is mostly about recall under pressure. An interview does not hand you a reference sheet, a search bar or unlimited time. It hands you a problem and watches what you do with it. Most people prepare by reading, which is the one form of practice that never puts them under that pressure.
This guide is a practical plan: what SQL interviews test, a topic checklist, a practice loop that uses quizzes well, an error log to turn mistakes into progress, and a checklist for the day itself.
In this guide
What SQL interviews test
Formats vary by company and role, but SQL usually shows up in one or more of these:
| Format | What it looks like | What it rewards |
|---|---|---|
| Online screening test | Timed multiple-choice or short queries | Fast, accurate recall of syntax and behaviour |
| Live SQL coding | Write queries in a shared editor while talking | Clear thinking, clarifying questions, testing your own work |
| Take-home or case study | Analyse a dataset and report findings | Correctness, judgement about what to include, communication |
| Discussion | Explain a past query, a bug or performance | Depth of understanding, not just syntax |
Interviewers are not grading only whether your query runs. They are looking at whether you ask about ties, NULLs and edge cases, and whether you can explain why your answer is right.
The topic checklist
Work through these in order and use the deep-dive guides where a topic feels shaky:
| Topic | A typical question | The classic trap | Guide |
|---|---|---|---|
| Joins | Customers who never ordered | INNER JOIN silently drops the rows you want | SQL Joins Explained |
| Aggregation | Customers with more than 3 orders | Filtering before vs after grouping | SQL WHERE vs HAVING |
| NULL handling | Count customers with a phone number | = NULL, NOT IN, COUNT(*) vs COUNT(col) | NULL in SQL |
| Subqueries and CTEs | Above the department average | Nested logic that becomes unreadable | Subquery vs CTE |
| Window functions | Top earner per department | Ties: RANK vs ROW_NUMBER | SQL Window Functions |
| Real questions | Second-highest salary, duplicates, streaks | The obvious answer is wrong | SQL Interview Questions |
Here are the links: joins, WHERE vs HAVING, NULL, subqueries and CTEs, window functions and nine worked interview questions.
The practice loop
- Learn one topic from the checklist.
- Quiz yourself on that topic only. A wrong answer points at a specific gap.
- Log every mistake (see below), including why you chose the wrong answer.
- Write the query again from a blank editor in our free SQL editor, without looking at the solution.
- Retake the topic a few days later. Recall that survives a gap is recall that will survive an interview.
- Mix topics under a timer once each one feels solid, because a real screening test does not tell you which technique to use.
- Explain your answer out loud. If you cannot say why it works, you do not fully know it yet.
Three ways to practise
| Mode | When to use it | How |
|---|---|---|
| Untimed, one topic | When a topic is new | Take your time, read every explanation |
| Timed, one topic | When the topic feels familiar | Add a timer and see if recall holds |
| Timed, mixed topics | In the last stretch before the interview | Random mix, so you must recognise the technique first |
A quiz format with a running clock, and an explanation you only see after you answer, is the closest free rehearsal for a live screen. Our SQL quiz works that way: free with a quick sign-in, every quiz timed and scored, and a written explanation for every answer. It will not feel comfortable, and that is the point. Comfortable practice does not prepare you for an uncomfortable moment.
Keep an error log
An interview is not graded on what you already knew. It is graded on the gaps. Reviewing what you got wrong tells you where to spend your next hour, while reviewing what you got right just feels good. Keep a simple log:
| Question | What I answered | Why it was wrong | Rule to remember |
|---|---|---|---|
| Customers with more than 1 completed order | HAVING COUNT(*) > 1 | Forgot to filter out cancelled orders first | Row filters go in WHERE, before grouping |
Here is that exact mistake, so you can see why it is easy to make. The table:
| order_id | customer_id | amount | status |
|---|---|---|---|
| 101 | 1 | 500 | completed |
| 102 | 1 | 300 | cancelled |
| 103 | 2 | 700 | completed |
My answer:
SELECT customer_id, COUNT(*) AS orders
FROM orders
GROUP BY customer_id
HAVING COUNT(*) > 1;
| customer_id | orders |
|---|---|
| 1 | 2 |
Customer 1 has two orders, but one is cancelled. Counting every row includes it. The fix: filter first with WHERE, then count.
SELECT customer_id, COUNT(*) AS completed_orders
FROM orders
WHERE status = 'completed'
GROUP BY customer_id
HAVING COUNT(*) > 1;
| customer_id | completed_orders |
|---|---|
| 0 rows returned | |
Writing the rule in your own words (“filter rows before grouping”) is what stops you repeating the mistake.
Want to run this yourself? Copy the setup SQL
CREATE TABLE orders (order_id INT, customer_id INT, amount INT, status VARCHAR(20));
INSERT INTO orders VALUES (101, 1, 500, 'completed'), (102, 1, 300, 'cancelled'), (103, 2, 700, 'completed');Works in MySQL, PostgreSQL and SQLite. Paste it into any of them, then run the queries from this guide.
Interview-day checklist
- Clarify before you type. Ask about ties, NULLs, duplicates and what should be excluded, such as cancelled or refunded orders.
- Say your plan first. “I will join the tables, group by department, then rank.”
- Build in small steps and check the intermediate result as you go.
- Test on a tiny example out loud, including an edge case such as a tie or a NULL.
- Name the trap you avoided. It shows you understand why the wrong answer is tempting.
- If you get stuck, say what you have tried and what you would check next. Silence is worse than a partial idea.
Frequently asked questions
How long should I prepare for a SQL interview?
It depends on your starting point and the role. What matters more than the number of days is coverage of the core topics (joins, aggregation, NULLs, subqueries, window functions) and repeated practice under time pressure.
What SQL topics should I prepare?
Joins, GROUP BY with HAVING, NULL handling, subqueries and CTEs, and window functions, plus the classic questions such as second-highest salary, duplicates and “never ordered” queries.
Are online quizzes good preparation for a SQL interview?
They are good for finding gaps and rehearsing recall under a timer. Pair them with writing queries from a blank editor and explaining your answers out loud.
Should I memorise SQL syntax?
Know the core well enough to write it without looking. For less common functions, it is fine to say which one you would use and check the exact syntax, as you would at work.
What if I get a question I do not know?
Talk through what you do know. State the goal, break it into steps and try the parts you can do. Interviewers usually value your reasoning as much as the final query.
Related reading
- SQL Interview Questions and Answers – nine worked questions with real outputs.
- SQL Quiz vs Tutorials – why testing yourself works better than re-reading.
- How to Learn SQL: A Practical Roadmap – if you are still building the basics.
Practise under a real timer
Free SQL quiz with a quick sign-in. Timed, scored, with an explanation for every answer.
Want a structured path instead?
Structured SQL courses – built for exactly this kind of interview prep.