Fabric Data Engineering, SQL

How to crack Data engineer SQL Interview -Day 3/60 Challenge

Hey there, future data engineers! I’m Adarsh Yadav, a data engineer who’s navigated the tough world of tech interviews and learned what it takes to succeed. Welcome to Day 1 of my 60-day SQL challenge, designed to help you master SQL for data engineer interviews and land your dream job at top companies like Meta, Google, Amazon, Netflix, and more. SQL is the heart of data engineering, accounting for 40–50% of interview questions. Over the next 60 days, I’ll share one real SQL interview question daily, sourced from candidate experiences on platforms like Glassdoor and LeetCode, or drawn from my own work as a data engineer.

This challenge will cover everything you need to excel in data engineer interviews, from basic joins and aggregations to advanced topics like subqueries, window functions, and query optimization. Each post will include a problem, a detailed solution, a schema/dataset for practice, and tips to boost your SQL skills. You can practice in any database—online tools like SQL Fiddle or offline ones like SQL Server, PostgreSQL or MySQL. I’ll explain solutions clearly in the comments and answer your questions to keep you motivated. If you stick with this challenge, I guarantee you’ll be ready to crush any SQL interview. Let’s dive into our first question from []

Why SQL Matters for Data Engineer Interviews

Data engineers are the backbone of data pipelines, transforming raw data into insights that drive business decisions. SQL is your go-to tool for querying large datasets, building reports, and designing data models. In data engineer interviews, companies test your ability to write efficient, accurate queries and solve real-world problems. For example, Meta might ask you to analyze social network data, Google could focus on user behavior metrics, and Amazon often tests e-commerce analytics. SQL questions make up 40–50% of the technical interview, so mastering it is critical.

This challenge is built to prepare you for those high-pressure moments. Each question will teach you how to think like a data engineer—logically, methodically, and practically. I will share practical tips from my experience, like how to structure queries for clarity or optimize for performance. By the end, you’ll not only write flawless SQL but also explain your solutions confidently, a key skill for data engineer interviews. Let’s get started with today’s [] problem!

Problem for Data Engineer:

In the last question for Amazon we have discussed about window functions Lead and lag.
Today we have another question which is asked in googles interview. In a recent Google interview question, you’re presented with a social network dataset and asked to find mutual friends between two specific users — Karl and Hans.

There’s only one user named Karl and one named Hans in the data. Your task is to write a query that returns their mutual friends, showing the user_id and user_name of each.

Company: Google

Level: Medium

Concepts Covered: Joins

Friends Table:

Users:

Expected Output:

Schema and Data Setup for Practice for Data Engineer

CREATE TABLE users(user_id INT, user_name varchar(30));
INSERT INTO users VALUES (1, 'Karl'), (2, 'Hans'), (3, 'Emma'), 
(4, 'Emma'), (5, 'Mike'), (6, 'Lucas'), (7, 'Sarah'), (8, 'Lucas'), 
(9, 'Anna'), (10, 'John');

CREATE TABLE friends(user_id INT, friend_id INT);
INSERT INTO friends VALUES (1,3),(1,5),(2,3),(2,4),(3,1)
,(3,2),(3,6),(4,7),(5,8),(6,9),(7,10),(8,6),(9,10),(10,7),(10,9);

Data engineer Approach:

Before jumping to my approach i will request you to spend some time to solve this.

To find common friend of Karls and Hans

  • First we will find friend of Karls and Hans in two differen tables or as CTE
select  friend_id from friends where user_id =1
select friend_id from friends where user_id=2
  • Then we can join the table based on friend-id

Solution:

with frinds_of_karl as (select  friend_id from friends where user_id =1 ),
friends_of_hans as (select friend_id from friends where user_id=2)
select u.user_id from users u
inner join frinds_of_karl fk on fk.friend_id=u.user_id
inner join friends_of_hans h on  h.friend_id= fk.friend_id

Explanation:

I don’t think so this question needs any explanation of my Data Engineering Family

Day 4: comming soon

Please go through other questions as well : 60 Days SQL Challange for Data engineers

Leave a Reply

Your email address will not be published. Required fields are marked *