Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
First and Last Result per Case
00:00
5 left

First and Last Result per Case

MediumSQL · PostgreSQL

Problem

Write a SQL query to find the first and last test result for each test case and environment.

Use the test_cases and test_results tables. The first result is determined by the earliest executed_at; if timestamps tie, use the smaller result_id first.

Output

  1. One row per test case and environment with at least one result.
  2. Columns: test_case_id, test_case_name, environment, first_result, and last_result.
  3. Sort by test_case_id, then environment.

Schema

test_cases
ColumnTypeDescription
test_case_idPKINTUnique identifier for the test case
test_case_nameVARCHAR(150)Descriptive name of the test case
test_suiteVARCHAR(100)Name of the suite containing the test case
test_results
ColumnTypeDescription
result_idPKINTUnique identifier for the test result
test_case_idINTReferenced test case
environmentVARCHAR(50)Environment where the test ran
result_statusVARCHAR(30)Outcome recorded for the test execution
executed_atTIMESTAMPTime when the test execution completed
Tablestest_casestest_results
Interviewer

Your question is First and Last Result per Case. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.