Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Find First Defect Created After Each Deployment
00:00
5 left

Find First Defect Created After Each Deployment

MediumSQL · PostgreSQL

Problem

Write a SQL query to find the first defect created after each deployment.

Use the deployments and defects tables. Match records by service; a defect qualifies only when it was created strictly after the deployment. Include deployments with no subsequent defect.

Output

  1. One row per deployment.
  2. Columns: deployment_id, service, deployed_at, defect_id, and defect_created_at.
  3. Return NULL defect values when no qualifying defect exists. Order by deployment_id ascending, breaking ties by the smallest defect_id.

Schema

deployments
ColumnTypeDescription
deployment_idPKINTUnique deployment identifier
serviceVARCHAR(100)Service deployed
deployed_atTIMESTAMPDeployment completion timestamp
defects
ColumnTypeDescription
defect_idPKINTUnique defect identifier
serviceVARCHAR(100)Service associated with the defect
created_atTIMESTAMPDefect creation timestamp
Tablesdeploymentsdefects
Interviewer

Your question is Find First Defect Created After Each Deployment. 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.