Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
First and Last Contact Events
00:00
5 left

First and Last Contact Events

MediumSQL · PostgreSQL

Problem

How would you use SQL window functions to identify the first and last provider contact events for each user on RealSelf?

Use the provided users and provider contact event records. Include only users with at least one provider contact event, and use event_id as the tie-breaker when timestamps match.

Output

  1. One row per qualifying user, ordered by user_id.
  2. Include user_id, user_name, first and last contact event IDs, timestamps, and provider IDs.

Schema

users
ColumnTypeDescription
user_idPKINTUnique RealSelf user identifier
user_nameVARCHAR(100)Display name of the user
created_atTIMESTAMPTimestamp when the user account was created
provider_contact_events
ColumnTypeDescription
event_idPKINTUnique contact event identifier
user_idINTUser associated with the event
provider_idINTProvider associated with the event
event_typeVARCHAR(40)Type of user event
contacted_atTIMESTAMPTimestamp when the event occurred
Tablesusersprovider_contact_events
Interviewer

Your question is First and Last Contact Events. 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.