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
Debugging SQL Queries
00:00
5 left

Debugging SQL Queries

MediumSQL · PostgreSQL

Problem

What are your strategies for debugging SQL queries?

Describe a systematic, PostgreSQL-focused approach using the provided execution and validation records. Write a query that surfaces executions requiring investigation, including failed executions and successful executions with failed validation checks.

Output

  1. One row per execution requiring investigation, with execution_id, query_name, status, error_message, and failed_check_count.
  2. Include executions with a non-success status or at least one failed validation check.
  3. Order by failed_check_count descending, execution timestamp descending, and execution_id ascending.

Schema

query_executions
ColumnTypeDescription
execution_idPKINTUnique query execution identifier
query_nameVARCHAR(100)Name of the executed SQL query
executed_atTIMESTAMPTimestamp when execution started
statusVARCHAR(20)Execution status
returned_rowsINTNumber of rows returned by the query
error_messageVARCHAR(255)Database error message when execution fails
query_validation_checks
ColumnTypeDescription
check_idPKINTUnique validation check identifier
execution_idINTReferenced query execution
check_nameVARCHAR(100)Name of the validation check
statusVARCHAR(20)Validation result status
observed_valueDECIMAL(12,2)Value observed by the check
expected_valueDECIMAL(12,2)Expected value for the check
notesVARCHAR(255)Additional validation details
Tablesquery_executionsquery_validation_checks
Interviewer

Your question is Debugging SQL Queries. 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.