SQL course · Interview and query mastery
SQL Interview & Query Mastery Course
Learn to write correct SQL, explain why it works, and check your result against real data. Follow a clear path from filtering rows to joins, aggregation, window functions and query reasoning.
For developers, analysts and career changers preparing for SQL-heavy interviews. Examples on this page use PostgreSQL syntax.
The interview habit
Define the result grain before you write the query.
GROUP BY customer_id
HAVING SUM(amount) >= 100
Course overview
A SQL interview preparation course built around reasoning.
Many SQL questions look short: return the right customers, calculate a total, or find the latest event. The difficult part is deciding what one result row represents, which records qualify, how missing values behave, and whether a join or grouping step changes the count. Syntax matters, but a correct answer also needs an explanation that survives a small change in the data.
This course outline gives you a structured way to learn those skills. Start by stating the requested output in plain English, identify the tables and keys, write a query in a stated dialect, and verify it against a tiny dataset before attempting a larger case. The sample lesson below lets you test that method now. SQL knowledge supports the broader technical interview preparation guide; this page focuses specifically on learning query design.
Use the curriculum map to choose your starting level, and use the completed lesson to judge the teaching approach. The live course offer, access details and purchase action are supplied by the synced pricing block below.
Course access
Choose your next step in SQL.
Review the current course options and access details here.
Heycademy Courses · Coming Soon
Master SQL with Heycademy
We’re preparing an interactive learning experience with practical exercises, skill assessments and personalized learning to help you build confidence and master new skills.
We’re putting the finishing touches on this course. Please check back for updates.
Starting point
Check your baseline before choosing a path.
A useful baseline is a set of small, independently checked tasks, not a claim that a single score proves mastery. Try four tasks without notes: filter rows by two conditions, join two tables without losing or multiplying rows unexpectedly, group records and apply an aggregate filter, and explain what a NULL does to a comparison. Record the expected output before running each query.
Result accuracy
Does your query return the exact rows and values on the sample data?
Reasoning
Can you name the grain, keys, filters and possible duplicate sources?
Transfer
Does the method still work when a new row or missing value appears?
This is a self-check framework. It does not imply that an automated Heycademy diagnostic or scoring feature is included with this course. If you are completely new to relational data, first learn what a table, row, column, key and relationship mean. Heycademy’s DBMS interview guide gives that broader database context.
What you will learn
The full SQL interview curriculum.
The progression begins with accurate row selection and ends with explaining performance trade-offs. Each topic has a practical output to check. The curriculum is a learning map; individual employers may use different SQL dialects, data models and interview formats.
| Topic | Beginner: make it correct | Intermediate: handle variation | Advanced: explain trade-offs |
|---|---|---|---|
| SELECT and filtering | Choose columns, filter with WHERE, sort and limit results. | Combine predicates, dates and calculated fields without changing the requested grain. | Explain predicate order, ambiguity and why a plausible filter gives a wrong result. |
| Joins and relationships | Identify join keys and match rows with INNER JOIN. | Use LEFT JOIN and check unmatched rows and duplicate expansion. | Reason about one-to-many joins and safely aggregate after joining. |
| Aggregation | Use COUNT, SUM, AVG and GROUP BY. | Choose WHERE versus HAVING and interpret COUNT(*) versus COUNT(column). | Explain distinct counts, null inputs and denominators in business metrics. |
| Subqueries and CTEs | Read a nested query and trace its output. | Use a subquery or CTE to name a reusable intermediate result. | Choose a readable decomposition and explain its effect on reasoning and execution. |
| Window functions | Understand the difference between grouped and row-preserving calculations. | Use ROW_NUMBER, RANK and partitioned aggregates. | Define ordering and tie behavior for top-N-per-group problems. |
| Nulls, indexes and validation | Test missing values with IS NULL and verify a small result by hand. | Diagnose outer-join filtering and inspect a basic execution plan. | Discuss index choices, selectivity and correctness before speed. |
Dialect note: examples here use PostgreSQL. Other engines may differ in date functions, quoting, row limits and execution-plan details. The relational reasoning transfers; check syntax against the database named in your interview.
For precise behavior, the PostgreSQL table-expression documentation explains joins, WHERE and GROUP BY; the official guides to CTEs, window functions and indexes provide deeper reference material.
Choose your route
Beginner, intermediate and advanced paths.
Beginner
Start with tables, keys, SELECT, WHERE, ORDER BY, simple joins and grouped totals. Work with tiny datasets where you can calculate the output yourself.
Move on when: you can describe every result row and predict whether a filter removes it.
Intermediate
Combine joins, aggregations, subqueries and CTEs. Solve questions that change the grain, such as one row per customer rather than one row per order.
Move on when: you can identify duplicate expansion and explain WHERE versus HAVING.
Advanced
Handle ranking, tie rules, nulls, performance choices and ambiguous requirements. Test edge cases and explain your trade-offs aloud.
Ready for a harder task when: your solution works on unseen rows and you can defend the result.
These are study stages, not certification levels or promised personalisation. A strong candidate may start at an intermediate topic and return to foundations when an error reveals a gap. Keep an error log with the misunderstood concept, corrected rule and one new test case.
Complete sample micro-lesson
When should a condition use WHERE or HAVING?
The interview task is: “Return customers whose paid orders total at least 100.” One result row should represent one customer. We will use a single orders table, so the lesson isolates filtering and aggregation. In a real database, check the table definition and monetary type before writing the final query.
| order_id | customer_id | status | amount |
|---|---|---|---|
| 1 | Ada | paid | 60 |
| 2 | Ada | paid | 45 |
| 3 | Ben | paid | 90 |
| 4 | Ben | pending | 40 |
| 5 | Cleo | paid | 120 |
| 6 | Cleo | refunded | 25 |
WHERE chooses order rows before they are grouped. GROUP BY customer_id forms one group per customer from the remaining rows. HAVING checks an aggregate condition after grouping. Here, “paid” is a property of each order, so it belongs in WHERE. “Total at least 100” is a property of each customer group, so it belongs in HAVING.
CREATE TEMP TABLE orders (
order_id integer PRIMARY KEY,
customer_id text NOT NULL,
status text NOT NULL,
amount numeric(10,2) NOT NULL
);
INSERT INTO orders VALUES
(1, 'Ada', 'paid', 60),
(2, 'Ada', 'paid', 45),
(3, 'Ben', 'paid', 90),
(4, 'Ben', 'pending', 40),
(5, 'Cleo', 'paid', 120),
(6, 'Cleo', 'refunded', 25);
SELECT customer_id, SUM(amount) AS paid_total
FROM orders
WHERE status = 'paid'
GROUP BY customer_id
HAVING SUM(amount) >= 100
ORDER BY customer_id;Expected output: Ada → 105.00; Cleo → 120.00. Ben’s paid total is 90.00, so he is excluded. The pending and refunded amounts never enter the totals. You can verify by hand: Ada has 60 + 45; Cleo has 120; Ben has 90.
New task: return each customer with at least two paid orders, along with their paid-order count. Do not return a customer merely because they have two orders of any status. Write the SQL and predict the row before checking below.
Show a complete answer and explanation
SELECT customer_id, COUNT(*) AS paid_orders
FROM orders
WHERE status = 'paid'
GROUP BY customer_id
HAVING COUNT(*) >= 2
ORDER BY customer_id;Result: Ada → 2. Ben has one paid order plus one pending order; Cleo has one paid order plus one refunded order. The row filter removes the latter two statuses before COUNT(*) runs. Using HAVING COUNT(*) >= 2 without the paid filter would incorrectly include Ben and Cleo.
Without changing the query, add (7, 'Ben', 'paid', 15). Which customers now meet the original “paid total at least 100” requirement? Predict the answer, run the INSERT and rerun the original SELECT. This is a transfer check: the solution should adapt to data it was not written around.
Show the check and reasoning
Ada remains at 105.00. Ben’s paid total becomes 90 + 15 = 105.00, so he now appears. Cleo remains at 120.00. The output is Ada, Ben and Cleo. If Ben does not appear, inspect the WHERE status filter and the HAVING threshold. If Ben appears at 145.00, the pending order was accidentally included.
The method generalises: identify whether each condition describes an input row or a grouped result, then test an edge case. In a join problem, first check whether the join multiplies rows before aggregating; that is a separate skill taught in the joins part of the map.
Your next step
Turn a correct query into a repeatable skill.
Use the course path to keep practising on fresh data and explaining each result.
Measure improvement
Track evidence, not just a completed lesson.
After each topic, solve one familiar task and one new task with altered data. Record four things: the expected output, your query, the actual output and a short explanation of any difference. A correct query you cannot explain is still a weak interview answer. A fluent explanation with the wrong rows also needs repair.
| Check | What to look for | If it fails |
|---|---|---|
| Output grain | One row per entity requested by the question. | Write “one row per …” before editing SQL. |
| Correct data | Expected and actual rows match on a tiny dataset. | List included and excluded input rows by hand. |
| Edge cases | Nulls, ties, duplicate joins and new rows are considered. | Add one counterexample and rerun the query. |
| Explanation | You can explain each clause and its order of effect. | Describe the intermediate result after each logical step. |
This rubric can be kept in a notebook or spreadsheet. It is a recommended study method, not a statement about tracking features inside the paid course. For interview practice, rehearse the explanation in plain language after the query is correct.
Course fit
Who this learning path helps.
Good fit
Developers who need to refresh everyday SQL before an interview; analysts who can use a database but struggle to explain query decisions; and beginners who know basic tables and want a structured route from SELECT to harder interview questions.
Check your needs first
If your target role asks for a specific engine such as SQL Server, MySQL or BigQuery, use this relational reasoning map but also practise that engine’s syntax and tooling. If the interview is mainly about database administration, schema migration or distributed systems, you will need additional material beyond this query-focused curriculum.
A useful SQL course should teach you to recover from a wrong answer: inspect the output, find the first clause that changes it incorrectly, and make a fresh test case. That is the distinction this page demonstrates through the worked lesson. It does not promise a particular interview score, hiring result or proprietary assessment format.
Questions before you begin
SQL course FAQs.
Do I need programming experience before studying SQL?
No general-purpose programming language is required for the first path. You do need to understand tables, rows and columns and be willing to run queries against a small sample database. A developer or analyst can start at the level where their query reasoning becomes unreliable.
Which SQL dialect do the examples use?
The runnable sample on this page uses PostgreSQL. SQL engines share many concepts, but syntax and behavior can differ for dates, quoting, limits and execution plans. Follow the dialect named in a job description or interview invitation.
What is the difference between learning SQL and practising SQL interview questions?
Learning builds a reusable model of tables, filters, joins, grouping and validation. Interview questions test whether you can apply that model to an unfamiliar prompt and explain the result. This course page prioritises learning the method, then checking it on new data.
How long should I spend on one topic?
Use the 15-minute lesson as a focused example, not a universal duration. Spend longer when you cannot predict the output or explain a failure. Move ahead when you can solve a fresh variation without copying the worked answer.
Will the course guarantee that I pass a SQL interview?
No course can guarantee an interview outcome. Interview content varies by employer and role. Aim for accurate results, clear reasoning and the ability to test your assumptions on unfamiliar data.
Where can I see access and pricing?
The synced course pricing block near the beginning of this page holds the current offer and purchase action. Check its displayed details before buying.
Further reading
Continue the surrounding skills.
These are educational navigation links. The course purchase action appears in the synced block above.
Ready to continue?
Build the SQL skills your next role asks for.
Return to the course options and choose the path that fits your starting point.