Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL First Message Per User

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

Your question is SQL First Message Per User. Start with the requirements and the one table 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

Tinder's messaging analytics team wants to identify the first message sent by each user. This helps measure how quickly new matches begin conversations.

Write a PostgreSQL query against user_messages to return the first message for every user with at least one non-null timestamp.

Requirements

  1. Use a window function to rank messages separately for each user_id.
  2. Select the earliest non-null timestamp for each user.
  3. If a user has multiple messages at the same timestamp, choose the lexicographically smallest message_id as the deterministic tie-breaker.
  4. Return user_id, message_id, and timestamp, ordered by user_id.

Schema

user_messages
ColumnTypeDescription
user_idINTEGERTinder user who sent the message
message_idPKVARCHAR(12)Unique identifier for the message
timestampTIMESTAMPTZTimestamp when the message was sent
Tablesuser_messages
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results