Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.