Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Join Massive Tables with Low Memory
00:00
5 left

Join Massive Tables with Low Memory

MediumSQL · PostgreSQL

Problem

Can you perform a join on two massive tables while minimizing memory usage?

Write a PostgreSQL query that returns matching active records from both tables. The approach should avoid unnecessary rows and columns before joining, while preserving duplicate matches for the same join key.

Output

  1. One row per matching pair of active records
  2. Columns: a_record_id, b_record_id, join_key, a_payload, b_payload
  3. Exclude inactive records and rows with no match
  4. Order by a_record_id, then b_record_id

Schema

massive_table_a
ColumnTypeDescription
record_idPKBIGINTUnique identifier for a record in table A
join_keyBIGINTKey used to match records across both tables
is_activeBOOLEANWhether the record is eligible for joining
payloadVARCHAR(100)Payload value from table A
massive_table_b
ColumnTypeDescription
record_idPKBIGINTUnique identifier for a record in table B
join_keyBIGINTKey used to match records across both tables
is_activeBOOLEANWhether the record is eligible for joining
payloadVARCHAR(100)Payload value from table B
Tablesmassive_table_amassive_table_b
Interviewer

Your question is Join Massive Tables with Low Memory. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.