Prepare For a SQL Interview

For data-related roles such as data scientists or data analysts, one of the interviews will inevitably be on SQL. This makes sense because SQL is what you use to extract data from databases, and as such is considered as an important fundamental skill set for the role.

One question people generally ask is, “How do I prepare for a SQL interview?” Here we will provide the answer to that question. We’ll start of with the general format of a SQL interview, then go into how to prepare for the interview, and finally we provide a few tips on what to do during the actual interview.

General format

In a SQL interview, the first five minutes or so will be spent on doing introductions. For this part, you should have a short script ready (no more than two minutes) that goes into your background and why you are interested in the role.

After that, the interviewer will dive into the questions. You should expect to answer multiple questions. This can be in the form of a single large question with multiple parts (i.e., the first part is easy, followed by parts with increasing difficulty), or it could be several questions that are unrelated to one another.

Often questions are related to the industry the company is in. For example, if you are interviewing with a social networking company, expect the questions to be related to social networking.

Usually the interview will be conducted over an online coding tool such as Coderpad or CodeSignal. Once you receive the question, you will then code your SQL in the tool. The interviewers will be logged into the same tool and can see in real time what you are typing in. Sometimes you can run the code to see if you get the right answer, but more often the interviewer will just be looking at your code to determine its quality. It is important to note that in the vast majority of the cases, the interviewer does not care about what flavor of SQL you use.

How to prepare

You’ll want to brush up on the following:

  • Aggregate functions and group by
  • Join (when to use outer join)
  • Union: A good number of questions will require you to answer in parts and then combine the results at the end. This is where UNION becomes handy.
  • Window functions: Inevitably you’ll run into a problem that requires you use Window functions to solve.
  • How the company works. This is useful because the SQL questions are usually related to the company itself. Understand how the company works can allow you to understand the question faster.

Get plenty of rest the night prior to the interview, and schedule your day of the interview so you are refresh for the interview. While this is true for all interviews, it is especially so for a SQL (or any other coding) interview because you are expected to be able to think on your feet, and a fresh mind gives you the best chance to be successful doing that.

There are also areas that you do NOT need to prepare for. Note that I have never seen the following topics:

I suspect that you don’t see the first three types because they are often database-dependent, and interviewers are usually interested in your general SQL skills, not in how good you are with a particular flavor of SQL.

For the “SQL background” type questions, you’ll often see those questions listed in the top results when you Google “SQL interview questions”, but in reality you never get them — interviewers are interested in how you can use SQL to solve problems, not whether you know SQL stands for Structured Query Language.

Interview Tips

You are prepared for the interview. Below are six tips for you to pass your interview:

1. Ask for clarifications. If there is anything in the interview question you are unsure of, make sure you ask the interviewer for clarification as opposed to make assumptions yourself. This is especially important if the question is domain-specific and you are not familiar with the domain.

2. Break down the question. When you get a question, break it down, and write your code based on how you are breaking things down. I recommend that you use WITH clauses to componentize your code. While it is possible to use subqueries for this purpose, I find using the with clauses to be easier for the interviewee to proceed and for the interviewer to follow.

3. Look at the instructions carefully. The reason is you don’t want to miss out on any filtering conditions. Did the question ask for only a particular time period? Did the question ask for top 10 overall or top 10 by country? These are details that the interviewer will pay attention to.

4. Talk out loud. Let the interviewer know your thought process. This makes it easy for the interviewer to follow your train of thought. And in case you are stuck or is going down the wrong path, the interviewer can guide you in the right direction.

5. Perfection is not necessary. If you have an idea on how to do something but at the same time you know it’s not the best way to proceed (and you don’t know what that “better way” is right at that moment), you should nevertheless go with the answer you know. Once you have something that works, the interviewer may ask (or you might want to mention yourself) that there could be a better way. The extra time you’ve bought for yourself may allow you to come up with the more elegant answer.

6. Ask for help. If you are really stuck, don’t be afraid to ask for help. Nothing is more awkward than a long silence. In most cases, the fact that you asked for help doesn’t mean that you have failed the interview. In fact, some questions are designed so that the interviewer expects the interviewee to struggle. As long as you can proceed to the right answer after the interviewer provides a hint, you should still be okay.

Summary

A technical SQL interview can be daunting, even for people who have used SQL for a while. By following the tips in this post on how to prepare and how to answer questions, you should be able to pass your SQL interview in flying colors.