Skip to main content

Command Palette

Search for a command to run...

LeetCode 175: Combine Two Tables

LeetCode 175 Explained: Merge Two Tables with Ease

Updated
1 min read
LeetCode 175: Combine Two Tables
V

I'm Varchasv, a Data Engineer working on enterprise data integration.

Currently on a 90-problem challenge to level up my technical skills and switch to a more development-focused role.

What I'm doing:

  • Solving 2 Leetcode problems daily (SQL + DSA).
  • Blogging about each problem.
  • Building in public.

My Goal - Land a better data engineering role by mid-2026.

Follow my journey !!

Date: January 13, 2026
Category: SQL
Time Taken: 2 minutes
Difficulty: Easy


Problem Statement

Table: Person and Address

Write a solution to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead.

Return the result table in any order.

Link: 175: Combine Two Tables


My Approach

Initial thought:
It looked like a pretty basic inner join at first glance, as we needed only 2 columns from each table, but it resulted in the wrong solution because we also need null values in case personId is not present in the Address table.

Final solution:
I used left join instead of inner join to combine the tables.

Why this works:
This works because the left join will also include the values that are null along with the common values.


Solution Code

SELECT firstName, lastName, city, state
FROM Person AS P
LEFT JOIN Address AS A
USING (personId)

Key Takeaway: Importance of Left and Right Joins.

Pattern: Table Join

Mistakes I Made: Chose Inner Join instead of Left Join.

Series: 90 Days of Data Engineering Progress: 1/90 problems completed

Tags: #LearnInPublic #DEQuest #LeetCode #SQL #DataEngineering

90 Days of Data Engineering

Part 2 of 48

Solving 90 problems over 18 weeks. Daily posts Mon-Fri. Goal: Switch to development role.

Up next

LeetCode 217: Contains Duplicates

An Easy Approach to LeetCode 217: Finding and Managing Duplicates