Career

How to Practice SQL for Interviews

By Owen Middleton · Updated November 2026

To practice SQL for interviews, solve problems that you have not seen before. Use a timer. Check your result against the expected result, row by row. In some online SQL tests, you get zero points for a result that is not an exact match.

Use the five steps below. Then try three graded tasks on this page, with your own timer.

We make SQLMaxx Learn, a free SQL course with graded problems.

What does a SQL interview test?

About SQL, Amazon tells candidates for business intelligence engineer (BIE) jobs: "Be prepared to write SQL queries and think about edge cases. You'll need to understand different types of joins and how condition filters affect the joins." This is one role at one company.

Amazon also describes its interview process for BIEs. The online assessment has three parts: "SQL Challenge, Working with SQL, and Work Styles". If you move forward, your next step is a technical phone screen or the interview loop. There are one or more phone screens, and each is 60 minutes. Amazon chooses the next step from the role and your assessment results. The loop is "five 55-minute interviews" (Amazon, BIE interview prep).

Companies can also make their own SQL tests on HackerRank. These tests are for job candidates. They are not the HackerRank certifications for developers. In its knowledge base for companies that make tests, HackerRank says: "HackerRank scores Database questions automatically by comparing the candidate's query result with the expected output." If your result is not the same as the expected output, HackerRank gives a score of zero. The question author can select "Ignore row order while matching output". HackerRank says that the employer can review a response manually and give partial credit. Source: HackerRank Knowledge Base, Database Questions.

Nick Singh, who made DataLemur, lists the topics in his guide. He writes that "SQL interviews typically cover five main topics": basic SQL commands, SQL joins, window functions, database design concepts, and "your ability to write SQL queries to answer business questions" (DataLemur, SQL interview guide).

How to practice SQL for an interview, step by step

In our view, here is how to learn SQL for an interview. First learn the topics. Then practice them in the conditions of the test, in five steps:

  1. Learn the SQL topics first. Use the topic list below. Start interview problems only when you can read the tables and the question of a problem.
  2. Solve problems that you have not seen before, with a timer. Nick Singh of DataLemur also tells you to "practice sql interview questions with a timer, and in the presence of a friend".
  3. Check your result against the expected result, row by row. Check the number of rows, the values and the row order.
  4. Say your steps aloud while you write the query. On its BIE page, Amazon tells candidates: "Think out loud as you work through the problem. This allows the interviewer to better follow and understand your thought process."
  5. On a later day, practice the topics again, with no notes. In SQLMaxx Learn, Review mode is for this: you practice the lessons that you mastered again. You need an account for Review mode.

Which SQL topics to practice for an interview, in order

Practice the topics in this order, from the SQLMaxx Learn course. This SQL roadmap for interview practice is our view. It is not a count of interview questions. Every SQLMaxx Learn lesson is free.

  1. SELECT, WHERE and ORDER BY on one table: lessons 1, 3 and 7 (Foundations tier).
  2. Aggregate functions, GROUP BY and HAVING: lessons 13 to 15 (Core SQL tier).
  3. Joins and a self-join (a join of a table to itself): lessons 17 to 22 (Core SQL tier). For the self-join, see Self-Joins, step by step (lesson 21).
  4. Subqueries and CTEs: lessons 24 to 26 (Core SQL tier), then lessons 30 and 31 (Intermediate tier).
  5. Window functions, then the rank functions ROW_NUMBER, RANK and DENSE_RANK: lessons 38 and 39 (Intermediate tier). To start, read Window Functions Introduction in practice (lesson 38).

In our view, practice joins and window functions most.

Try three SQL interview practice tasks

Use these three tasks to practice. Each task has a check of the exact result. The tasks on this page have no timer.

HackerRank recommends these times to authors of Database questions: Easy, 15 minutes (50 points); Medium, 30 minutes (75 points); Hard, 45-60 minutes (100 points). In SQLMaxx Learn, task 1 is a hard problem, and tasks 2 and 3 are medium problems. In our view, use the HackerRank times as a guide. Set a timer to 45 minutes for task 1 and to 30 minutes for tasks 2 and 3.

For the tasks, use three tables of Brightlane, a made-up online store: categories, orders and products. In categories, the parent_id of a category is the id of its parent category.

Schema · ecommerce3 tables? = nullable
categories
idinteger
nametext
parent_id?integer
orders
idinteger
customer_id?integer
ordered_attimestamptz
statustext
total_amountnumeric
products
idinteger
nametext
category_id?integer
pricenumeric
stock_qtyinteger
attributes?jsonb

Three SQL interview tasks on store data

Each task is a problem from SQLMaxx Learn. We added a sort order to each. Task 1 is from lesson 21, "Self-Joins". Task 2 is from lesson 38, "Window Functions Introduction (OVER, PARTITION BY)". Task 3 is from lesson 39, "ROW_NUMBER, RANK, DENSE_RANK". Write the query in the editor. Then press "Check task 1", "Check task 2" or "Check task 3".

After you try: notes on the edge cases

After each task, look at the edge cases, as Amazon tells BIE candidates to do:

  • Task 1: you get 14 rows. For the 4 top categories (parent_id is NULL), you get no rows. An interviewer can also ask for each pair one time only. For that version, keep the rows where the first id is smaller than the second. Then you get 7 rows.
  • Task 2: with GROUP BY on customer_id, you get 62 rows, one for each customer. For this task, you need 200 rows, one for each order.
  • Task 3: in category 4, two books have the same price, 44.99, so both have rank 3. The next book has rank 5. The 3 products with no category are one group.

If you solved a task, explain your query aloud in two sentences, as you would to an interviewer.

Where is the best place to practice SQL for interviews?

In our view, the best place to practice SQL for interviews has interview-style problems and a check of your result. These four sites have interview-style SQL problems. We list them in alphabetical order, and we do not rank them.

  • DataLemur SQL questions. DataLemur links its lessons to real SQL interview questions from companies such as Amazon and Microsoft. With no account, DataLemur shows 54 SQL questions in its question list, and DataLemur shows no Premium mark on them. DataLemur does not list its Premium SQL questions there. For example, "Ad Campaign ROAS" is a Premium question, and it is not in the list. DataLemur also does not list the 4 SQL questions that we found with a referral task. On these questions, DataLemur shows "To view this question you must complete referral task". How we know it: We used a free account and paid for nothing.
  • HackerRank SQL practice challenges. You can filter the SQL challenges by the three levels of the free HackerRank SQL certificate tests: SQL (Basic), SQL (Intermediate), and SQL (Advanced). HackerRank lists 58 SQL challenges. HackerRank SQL (Basic) certificate test: For SQL (Basic), you take a 30-minute assessment and solve 2 questions. How we know it: We used a free account and paid for nothing.
  • LeetCode Database problems. LeetCode has 323 Database problems, and on each of the 105 free ones, you can answer in four SQL engines. You must log in or sign up to run or submit a query. How we know it: We used a free account and paid for nothing.
  • StrataScratch. StrataScratch has 750 Analytical interview questions, and with the paid plan, you get solutions, hints and walkthroughs for all of them. With no payment, you get 71 of the 750 Analytical questions. StrataScratch says that AI guidance is in the paid plans only. How we know it: We audited it free.

For scores on these sites and others, read our guide on where to practice SQL.

SQLMaxx Learn has 615 free graded problems, but they are course problems in PostgreSQL, not company interview questions.

Start SQLMaxx Learn lesson 1

SQLMaxx Learn is free. See the course from SELECT to window functions: all 66 lessons on one page. Lesson 1 is "SELECT and Column Expressions", and you can start it in your browser with no account.

SQLMaxx Learn has two modes, Learn and Review. In Learn mode, you study new lessons and solve their problems.

More questions about SQL interview practice

Is SQL 50 enough for an interview?

In our view, not on its own. There are 50 Database problems in the SQL 50 study plan, and all 50 are free. You still log in to run or submit a query. In our view, with SQL 50 you practice many core topics. But after you solve it, the problems are not new to you. Then practice on problems that you have not seen before.

Can you give me some practice SQL interview questions?

Yes. Here are the free questions on two interview sites. LeetCode: You can open 105 of the 323 Database problems free. You need Premium for the other 218. StrataScratch, on its pricing page: StrataScratch charges $0 for the Free plan, and you need no card. StrataScratch lists "75+" coding questions with solutions in the Free plan. For graded practice in your browser, try the three tasks on this page.

Does a SQL interview test only SQL?

Not always. On its page for business intelligence engineers, Amazon lists four technical competencies, and only one of them names SQL: "SQL and Basic scripting", "Analytical problem solving", "Visualization, metrics and reporting" and "Business acumen/requirements gathering". For more about the skills next to SQL, read our guide on jobs with only SQL. Source: Amazon, BIE interview prep.

Should I build SQL projects before a SQL interview?

In our view, yes, if you have the time. With a project, you have a query of your own to explain in the interview. Choose one of your SQL projects for a portfolio, and practice how you explain its main query.