Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL indexing fundamentals
00:00
5 left

SQL indexing fundamentals

MediumSQL · PostgreSQL

Problem

How does SQL indexing work and when does an index help or hurt?

Asked in the Round 1 - technical screen stage. Listed as 'SQL indexing'. For the hands-on portion, use the supplied tables to return qualifying events and identify indexes that could support the query.

Output

  1. One row per qualifying event, with event_id, file_name, event_type, occurred_at, and user_name
  2. Include events from 2026-01-01 onward only when the associated user is active
  3. Order by occurred_at descending, then event_id ascending

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User display name
is_activeBOOLEANWhether the user is currently active
file_events
ColumnTypeDescription
event_idPKINTUnique event identifier
user_idINTUser associated with the event
file_nameVARCHAR(150)Name of the affected file
event_typeVARCHAR(30)Type of file event
occurred_atTIMESTAMPTime when the event occurred
Tablesusersfile_events
Interviewer

Your question is SQL indexing fundamentals. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.