Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Shared Names Pairs

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Find Shared Names Pairs. Start with the requirements and the two tables on the right.

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.

Problem

Given two tables (User_age and user_names), find all pairs of userids sharing the same name, returning userid_1, userid_2, and name without duplicates (excluding reverse pairs).

Asked in the SQL and coding round stage. A commenter separately confirmed Meta asks this same question in Solutions Architect interviews.

Output

  1. Return one row per unordered pair of users represented in both tables.
  2. Columns must be userid_1, userid_2, and name.
  3. Exclude rows where name is NULL, and ensure userid_1 is less than userid_2.
  4. Order by name, userid_1, and userid_2 ascending.

Schema

User_age
ColumnTypeDescription
useridPKINTEGERUnique user identifier
ageINTEGERUser age, when available
user_names
ColumnTypeDescription
useridPKINTEGERUser identifier referencing User_age
nameVARCHAR(100)User display name
TablesUser_ageuser_names
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results