Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Most Recent Defect Per Test
00:00
5 left

SQL Most Recent Defect Per Test

MediumSQL · PostgreSQL

Problem

Write an SQL query to identify the most recent defect for each test case.

Return all test cases, including those without a linked defect. The most recent defect is determined by the latest reported_at timestamp; if timestamps tie, choose the defect with the greatest defect_id.

Output

  1. One row per test case, ordered by test_case_id.
  2. Columns: test_case_id, test_case_name, defect_id, defect_title, reported_at, and severity.
  3. Test cases without defects must have NULL values for defect columns.

Schema

test_cases
ColumnTypeDescription
test_case_idPKINTUnique test case identifier
test_case_nameVARCHAR(150)Test case name
test_suiteVARCHAR(100)Test suite containing the case
defects
ColumnTypeDescription
defect_idPKINTUnique defect identifier
defect_titleVARCHAR(200)Short defect description
reported_atTIMESTAMPTimestamp when the defect was reported
severityVARCHAR(20)Defect severity
test_case_defects
ColumnTypeDescription
test_case_idPKINTReferenced test case
defect_idPKINTReferenced defect
link_statusVARCHAR(20)Status of the test case to defect relationship
Tablestest_casesdefectstest_case_defects
Interviewer

Your question is SQL Most Recent Defect Per Test. Start with the requirements and the three 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.