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
Insert User with Unique Phone
00:00
5 left

Insert User with Unique Phone

MediumSQL · PostgreSQL

Problem

In a single SQL query, insert a new user with a phone number and make sure phone number is unique.

Asked in the Technical Round 1 stage. Reported follow-ups included the benefits of UNIQUE and which data structure implements indexing.

Output

  1. Return user_id, full_name, and phone_number for the inserted user.
  2. Insert the user only if the phone number is not already present.
  3. Return at most one row, with no required ordering.

Schema

users
ColumnTypeDescription
user_idPKINTGenerated identifier for the user
full_nameVARCHAR(100)User's full name
phone_numberVARCHAR(20)User phone number with a UNIQUE constraint
Tablesusers
Interviewer

Your question is Insert User with Unique Phone. Start with the requirements and the one table 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.