Longest Running Pipeline

A medium SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
medium
Seniority
L3
Asked in
City and County of San Francisco

Problem

An on-call engineer chasing a slow batch window is going through data_pipes, which records every pipeline run along with how long it took. Return the name of the one pipeline behind the longest recorded run.

One pipeline outlasted them all.

Tables

data_pipes

Columns: pipe_id INTEGER, pipe_name TEXT, status TEXT, rows_in INTEGER, rows_out INTEGER, start_at TEXT, dur_secs INTEGER

data_pipes: 10 of 200 rows
pipe_idpipe_namestatusrows_inrows_outstart_atdur_secs
131etl_usersfailed137972026-02-02 01:00:0028
162etl_eventsrunning2741942026-03-03 02:00:0051
193sync_crmqueued4112912026-04-04 03:00:0074
224agg_dailyskipped5483882026-05-05 04:00:0097
255agg_weeklySuccess6854852026-06-06 05:00:00NULL
286export_s3FAILED8225822026-07-07 06:00:00143
317import_csvsuccessNULL6792026-08-08 07:00:00166
348ml_trainfailed10967762026-09-09 08:00:00189
379dbt_buildrunning1233NULL2026-01-10 09:00:00212
410etl_ordersqueued13709702026-02-11 10:00:00NULL

Expected output

First 1 of 1 rows
pipe_name
dbt_build

Worked solution and explanation

Why this problem exists in real interviews

Against the data_pipes table, top-N selection and running total on pipe_name values is the key operation. Interviewers favor this in mid-level screens because it exposes whether candidates handle ties, NULLs, and ordering edge cases correctly.


Break down the requirements

Step 1: Read from data_pipes

The query targets data_pipes with 7 columns. Identify which columns are needed for the output.

Step 2: Order and limit the output

Sort by the target metric and apply LIMIT to return the requested number of rows. Ensure the sort is deterministic to produce reproducible results.

Step 3: Return the result set

Select the required columns with any necessary aliasing or formatting.


The solution

Direct sort for longest pipeline
SELECT pipe_name
FROM data_pipes
ORDER BY dur_secs DESC
LIMIT 1

Common follow-up questions