16th Jan 2025 15 minutes read Meta SQL Interview Questions Jill Thornhill SQL Interview Questions Jobs And Career Table of Contents The Meta Recruiting Process Initial Call With a Recruiter First Interview Coding Interview Hints and Tips Design Interview Behavioral Interview What Meta Roles Require SQL Knowledge? Preparing for Your Meta SQL Interview Meta SQL Interview Questions: Theory Question 1: SQL JOINs Question 2: WHERE vs. HAVING Question 3: Constraints Question 4: Transactions Question 5: Stored Procedures vs. Functions Question 6: SQL Injection Meta SQL Interview Questions: Practical Question 1: Usage Statistics Thinking It Through Sample Answer Question 2: Identify Active Event Hosts Thinking it Through Sample Answer Question 3: Find the Top Power Users Thinking it Through Sample Answer Question 4: Analyze Year-on-Year User Activity Thinking it Through Sample Answer Finding Resources for Your Meta SQL Interview Preparation Meta SQL interviews are tough, and you need to hone your skills if you’re to land a prestigious and well-paid job. Read on to find out what kind of SQL interview questions you may be asked in a Meta interview, how best to prepare, and how to stand out from the crowd. Meta is a highly data-driven company, one that uses a wide variety of database technologies. MySQL is their primary database, but they also have special-purpose databases for various applications. Whatever role you’re applying for, chances are you will have some interaction with databases. Meta is more likely than most companies to include SQL-related questions in interviews. If you’re thinking of applying for a job at Meta, it’s worth looking at sample Meta SQL interview questions and getting as much practice as you can. If you’re not yet familiar with SQL, you might like to enroll in our SQL From A to Z learning track. This set of courses takes you from beginner-level all the way to advanced SQL topics. You’ll gain practical experience by working through more than 700 guided exercises – as well as becoming familiar with the concepts of relational databases. If you have some experience with SQL but haven’t used many of its advanced features, our Advanced SQL course may suit you better. In all our tracks and courses, you’ll access a database through your Internet browser; no need to download or install anything. Plus, help is available at every step. Now, let’s suppose you know some SQL and you’re interested in working for Meta. What should you expect during a Meta SQL job interview? The Meta Recruiting Process Meta recruiters will assess your technical background, your problem-solving abilities, and your ability to work well within a team. The entire process is likely to take two to three months and involve several rounds of interviews. Your first step is to create a career profile at Meta. If you haven’t already done this, you can visit the Create a Career Profile page to get started. From within your profile, you can view recommended jobs and create job alerts. You’ll also find a host of useful resources, including interview preparation guides and practice exercises. Once you’ve applied for a job, you’ll receive role-specific preparation materials via your profile. Let’s look at the interview stages you’ll go through once you’ve submitted a job application. Initial Call With a Recruiter What to expect: You’ll be asked about your background, experience and goals. You’ll also be asked why you want to work at Meta. The recruiter will tell you more about the role and the team you’ll be working with. How to prepare: As soon as you’ve applied for the job, take the time to: Make sure you’re familiar with the job description. Review your relevant experience and think about how you can best showcase it to the recruiter. Make a list of questions to ask the recruiter. First Interview What to expect: This interview may be via phone or (more likely) an online meeting platform. You’ll meet some of the Meta team and learn more about the role and who you’ll be working with. How to prepare: Your recruiter will help you prepare for this interview and provide any materials you may need. Coding Interview What to expect: If you’ve applied for roles like data analyst or marketing analyst, the coding language may be SQL. The interview will take 45 minutes, 35 of which are set aside for you to solve two medium-to-hard coding questions. This interview may be conducted in person or online. How to prepare: Your recruiter will provide material that will help you prepare for the interview. The best way to get ready for this interview is practice, practice, and more practice! You’ll also need to make sure you’re very familiar with the target programming language’s What the interviewer is looking for: You’ll be assessed on your: Technical expertise. Problem-solving skills. Communication style. Ability to verify your solution with relevant test data. Hints and Tips The interviewer is assessing your communication skills, so make sure you: Ask questions before you start, so you can make sure you’ve understood the problem correctly. Are prepared to explain to the interviewer why you’ve chosen that approach to the problem. Listen carefully to any comments the interviewer makes: they may be hinting that you’re taking the wrong approach. Ask the interviewer if you’re unsure whether you’re allowed to use a specific functionality (g. non-standard functions) in your solution. Additionally, remember that: The interviewer is also trying to assess the way you approach problems, so think out loud as you work. Be aware of performance issues – e.g. is your solution likely to be slow or to use too much space in temporary tables? You won’t be entering your solution into a database, so you won’t have any help with syntax and you can’t try things out. If your interview is in person, you’ll write your solution on a whiteboard; otherwise, you’ll be working in a simple text editor. Perfect syntax is less important than demonstrating that you can solve complex problems. If you can see more than one solution to the problem, ask the interviewer if it’s OK to go with the one you prefer. If you’ve seen the question before, say so. The interviewer wants to assess how you work through a new problem; it will be obvious to them if you already know the answer. Finally, don’t forget to review the sample data you’ll use to test your solution. Design Interview This may not apply for some roles – for example, data analysts may instead have an interview related to statistical knowledge. But in this interview, you may be asked to create a high-level design for a typical real-world application. You may need to demonstrate your understanding of RDBMS concepts, so make sure you’re up to speed in this area. Behavioral Interview This interview assesses whether you’ll be a good fit for the team. What Meta Roles Require SQL Knowledge? Most roles at Meta will involve a certain amount of database interactions. Here are some of the roles where you may encounter SQL interview questions: Data scientist Data analyst Software engineer Product analyst Business analyst Machine Learning engineer Marketing analyst Database administrator Technical program manager Growth analyst Preparing for Your Meta SQL Interview Before you begin applying for a job at Meta, you should become familiar with their products – e.g. Facebook, WhatsApp, Messenger, and Instagram. Try to visualize what might be going on behind the scenes and what underlying data these products use. Read about their company culture and goals and download Meta’s interview preparation guide. You can also watch Meta’s coding interview video to get a better idea of what to expect. You’ll need lots of practice with the type of questions you may be asked at a Meta interview. Try working with only a simple text editor to enter your answers and thinking aloud as you solve problems. This will help you get used to this part of the technical interview. Before you start practicing, you may want to take our SQL Skills Assessment to get a better idea of areas where you need to improve. We also have several free, downloadable cheatsheets you can use to help you review your knowledge: SQL Interview Cheatsheet SQL Joins Cheatsheet Window Functions Cheatsheet Meta SQL Interview Questions: Theory Let’s now look at some practice questions that will give you an idea of what to expect at a Meta SQL interview. They’re split into two types: theoretical and practical. You may be asked theoretical questions during one of the verbal interviews. Or the topics may come up when you’re discussing your solutions in the design interview. The practical questions are similar to the problems you may be asked to solve during the coding interview. Question 1: SQL JOINs What’s the difference between an INNER JOIN and an OUTER JOIN in SQL? An INNER JOIN returns only rows that are matched in both tables. An OUTER JOIN includes unmatched rows in the result according to the following rules: LEFT JOIN returns all rows in the left-hand table alongside either the matching row from the right-hand table or nulls. RIGHT JOIN returns all rows in the right-hand table alongside either the matching row from the left-hand table or nulls. FULL JOIN returns all rows from both tables. Question 2: WHERE vs. HAVING What’s the difference between the use of the WHERE clause and the HAVING clause? The WHERE clause filters individual rows for certain conditions, whereas the HAVING clause filters groups of rows by aggregate conditions. Thus, HAVING can only be used with the GROUP BY clause. Question 3: Constraints Describe three types of SQL constraints. Constraints enforce rules that apply when rows are being inserted, updated, or deleted in the database; they are defined when a table is created. There are several types of constraints, so you could pick any three of the following: NOT NULL specifies that a column may not contain nulls. UNIQUE specifies that values in this column cannot be duplicated within the table. PRIMARY KEY specifies that this column will be used as the table’s primary key, i.e. the values must be unique and non-null so they can identify each row. FOREIGN KEY specifies that this column will link to the primary key in another table. This enforces referential integrity. CHECK defines a condition to allow only specific values in this column. DEFAULT specifies a value that will be used if no value is specified when data is inserted into this column. AUTO_INCREMENT specifies that the column will automatically be set to the next number in sequence on an insert. Question 4: Transactions Explain what is meant by a transaction in SQL. What will happen if the server crashes halfway through a transaction? A transaction is a group of updates that must be carried out as a unit: either all the updates must be carried out or none of them. An example could be a customer’s purchase, which updates the customer table, the sales table, the stock table, and the cashbook. All of these must be successfully updated if the transaction is to succeed. Once all are updated, you can commit the transaction and the database will be permanently updated. Or you can rollback the transaction, in which case no changes will be made to the database. If the system crashes, none of the updates are made permanent and the database will not reflect the transaction. Question 5: Stored Procedures vs. Functions What’s the difference between a stored procedure and a function in SQL? Give an example of when each one may be used. A stored procedure is a set of predefined SQL statements that carry out a task. Stored procedures may optionally return one or more values and may take parameters. They’re invoked using the CALL statement. Examples may include extracting data for a report or carrying out year-end cleardown procedures. Functions are also a set of predefined SQL statements, but they always return exactly one object. The object may be a value or a table. Functions optionally take parameters and can be used within SQL statements in the same way as database columns. Examples include carrying out calculations to incorporate business rules and carrying out custom formatting. Question 6: SQL Injection What’s SQL injection (SQLi)? Describe two ways a programmer could guard against an SQLi attack. SQL injection is a way of injecting malicious code into an SQL statement, usually to fraudulently update the database. Imagine a program that constructs an SQL statement as a text string. When customers make online requests, they supply details that will be used in the SQL code. As a very simple example, the program may build an SQL statement from the text SELECT * FROM customer WHERE account_no = suffixed by the account number entered by the client. If the client enters the account number as 12404; UPDATE customer SET balance_owing = 0 WHERE account_no = 12404, the malicious update statement is injected into the database. Two ways a programmer could guard against this are: Run some checks on the resulting SQL statement before executing it. Use prepared statements, so that the account number is used as a parameter rather than to construct the statement. Meta SQL Interview Questions: Practical For the purpose of the practical SQL interview questions, let’s assume a database that holds the following tables and columns. Table nameUsersPostsEventevent_activityinteractions containsuser_idpost_idevent_idevent_act_idinter_id thenameuser_idHostevent_idaction rows:locationdatetime_posteddatetime_eventuser_iduser_id date_joineddetailsDetailsdatetime_acttarget_type response_typetarget_id Question 1: Usage Statistics Calculate the percentage of users who have not posted this year. Thinking It Through You could approach this in several different ways. The simplest is probably to use a common table expression (CTE) to count the number of distinct users in the posts table where the year portion of the date is the same as the year portion of the current date. You can then write a simple query to count the number of users in the users table, join this to the CTE table, and do a calculation to get the percentage. Sample Answer WITH posting_users AS ( SELECT COUNT(DISTINCT user_id) AS posting_users FROM posts WHERE year(datetime_posted) = year(current_date) ) SELECT 100 - (posting_users / COUNT(*) * 100) AS percent_inactive FROM users JOIN posting_users; Question 2: Identify Active Event Hosts List the user ID, user name, number of events, and the total number of event attendees for all users who have scheduled more than 10 events this year. Additional info: Acceptances are rows in the event_activity table that have the response type ‘Going’. The host in the events table can be matched to the user ID in the users table to find the user who scheduled the event. Thinking it Through You’ll need to join the event table, the event_activity table and the users table to get all the right information. The event_activity table should use a LEFT JOIN, since you haven’t been told to exclude events that have no attendees. This join should include the condition that the response must be ‘Going’. Grouping by the host, you can include a distinct count of the event ID to get the number of events and a count of the user_id in the event_activity table to get the number of attendees. You’ll need to include a HAVING clause to filter by the number of events. Sample Answer SELECT host, name, COUNT(DISTINCT e.event_id), COUNT(a.user_id) AS attendees FROM event e JOIN users u ON u.user_id = host LEFT JOIN event_activity a ON e.event_id = a.event_id AND response_type = 'Going' GROUP BY host, name HAVING COUNT(DISTINCT e.event_id) > 10 ORDER BY name Question 3: Find the Top Power Users Find the top 10 power users (ranked by the total number of likes on their posts) and list their ranking, user ID, name, and total number of likes. Additional info: Power users are defined as users who have made more than 500 posts this year and have an average of more than 150 likes per post. Likes on posts are recorded in the interactions table with action containing ‘Like’ and target_type containing ‘Post’. The target ID can be used to join to the posts table on the post ID. Thinking it Through You’ll first need to find the number of posts and the number of likes for each user for this year. You could do this with a CTE. In the main query, you can join the CTE with the users table to pick up the user’s name. Filter the CTE to extract only the power users. You can use the RANK() window function to rank the users by number of likes and use the LIMIT clause to limit the results to the top 10 power users. Sample Answer WITH user_posts AS ( SELECT p.user_id, COUNT(DISTINCT post_id) AS num_posts, COUNT(inter_id) AS likes FROM posts p LEFT JOIN interactions ON post_id = target_id AND target_type = 'POST' AND action = 'Like' WHERE year(datetime_posted) = year(current_date) GROUP BY user_id ) SELECT RANK() OVER (ORDER BY likes DESC) AS position, u.user_id, name, likes FROM users u JOIN user_posts p ON u.user_id = p.user_id WHERE num_posts > 500 AND likes/num_posts > 150 LIMIT 10; Question 4: Analyze Year-on-Year User Activity For the past 5 years, compare the number of active users year-on-year. Show the year, the total active users, and the change from the previous year. Additional info: Active users have made at least one post during the year. Thinking it Through You’ll need to extract a count of the number of users by year from the posts table. For readability, you can do this as a CTE. You’ll then need to use the LAG() window function to compare year-over-year results. Sample Answer WITH activity AS ( SELECT year(datetime_posted) AS year, COUNT(distinct user_id) AS active_users FROM posts WHERE year(current_date) - year(datetime_posted) < 6 GROUP BY year(datetime_posted) ) SELECT year, active_users, (active_users - LAG(active_users) OVER (ORDER BY year) ) * 100/active_users AS percentage_change FROM activity; Finding Resources for Your Meta SQL Interview Preparation The most important way to prepare is to solve a wide range of practice problems. You should aim to confidently solve two medium-to-hard questions in 35 minutes. Remember to think out loud as you work on your solution. Use either a text editor or pen and paper to develop your solution to simulate the interview situation. Of course, you can try out your solutions on a real database afterwards to make sure they work. In the interview, you’ll likely be using coderpad.io, so it’s worth trying it out beforehand. Take time to explore the preparation hub in your Meta career profile. You’ll find lots of useful material, including coding puzzles you can use for practice. LearnSQL.com has several useful practice and interview resources: Advanced Interview Questions Tricky Interview Questions SQL Interview Questions for Data Analysts Perhaps the most valuable practice resource is LearnSQL.com’s Advanced Practice Track where you can work through hundreds of realistic examples. You can try your solutions on a real database, and get hints and tips when you get stuck. Get started today and ace that interview! Tags: SQL Interview Questions Jobs And Career