Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Most Recent Passing Test Per Module

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Most Recent Passing Test Per Module. Start with the requirements and the two tables on the right.

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.

Problem

Apex Systems QA engineers review automated test execution history across product modules. Write a PostgreSQL query that reports the most recent passing test for every module, including modules that have no passing test.

Requirements

  1. Return every module from modules, even when it has no test run or no passing test.
  2. Consider only rows where test_runs.status = 'PASS'.
  3. Select the latest passing run by executed_at. If multiple passing runs have the same timestamp, choose the row with the greatest test_run_id.
  4. Return the module ID, module name, selected test run ID, and execution timestamp, ordered by module ID.

Schema

modules
ColumnTypeDescription
module_idPKINTEGERUnique identifier for a product module
module_nameVARCHAR(100)Human-readable module name
test_runs
ColumnTypeDescription
test_run_idPKINTEGERUnique identifier for a test execution
module_idINTEGERModule tested by the run
statusVARCHAR(20)Test outcome
executed_atTIMESTAMPCompletion timestamp of the test run
Tablesmodulestest_runs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results