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
Optimize Slow Multi-Join SQL
00:00
5 left

Optimize Slow Multi-Join SQL

HardSQL · PostgreSQL

Problem

How do you optimize a slow-performing SQL query that involves multiple joins on large consumer databases at Ipsos?

Write a PostgreSQL query that returns the requested result while demonstrating an efficient approach for filtering, joining, and aggregating large survey datasets. The query should preserve valid completed responses and avoid unnecessary row multiplication.

Output

  1. One row per qualifying survey project and consumer region.
  2. Return project_id, region_code, completed_response_count, unique_consumer_count, and average_metric_score.
  3. Include launched projects and completed responses from 2025 with a non-null target metric question.
  4. Order by project_id ascending, then region_code ascending, with NULL regions last.

Schema

consumers
ColumnTypeDescription
consumer_idPKINTUnique consumer identifier
region_codeVARCHAR(20)Consumer geographic region
age_bandVARCHAR(20)Consumer age category
consent_statusVARCHAR(20)Research participation consent state
survey_projects
ColumnTypeDescription
project_idPKINTSurvey project identifier
project_nameVARCHAR(150)Ipsos survey project name
field_startDATEFieldwork start date
field_endDATEFieldwork end date
statusVARCHAR(20)Project lifecycle status
survey_responses
ColumnTypeDescription
response_idPKINTSurvey response identifier
project_idINTReferenced survey project
consumer_idINTReferenced consumer
completed_atTIMESTAMPResponse completion timestamp
response_statusVARCHAR(20)Response completion state
response_answers
ColumnTypeDescription
answer_idPKINTAnswer row identifier
response_idINTReferenced survey response
question_idINTReferenced survey question
numeric_valueNUMERIC(8,2)Numeric answer value
questions
ColumnTypeDescription
question_idPKINTQuestion identifier
metric_nameVARCHAR(100)Metric represented by the question
is_target_metricBOOLEANWhether the question contributes to the requested metric
Tablesconsumerssurvey_projectssurvey_responsesresponse_answersquestions
Interviewer

Your question is Optimize Slow Multi-Join SQL. Start with the requirements and the five 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.