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
Discrepancy Query Between Sources
00:00
5 left

Discrepancy Query Between Sources

HardSQL · PostgreSQL

Problem

Write a SQL query to identify discrepancies between two data sources.

Compare records using record_id. Identify records missing from either source, records duplicated within a source, and records whose aggregated amount or status differs. Treat NULL statuses as distinct from non-NULL statuses.

Output

  1. One row per discrepant record_id
  2. Columns: record_id, discrepancy_type, source_a_count, source_b_count, source_a_amount, source_b_amount, source_a_status, source_b_status
  3. Include only discrepant records and order by record_id ascending.

Schema

source_a_records
ColumnTypeDescription
source_row_idPKINTUnique row identifier in source A
record_idINTBusiness record identifier
amountNUMERIC(12,2)Amount reported by source A
statusVARCHAR(30)Record status reported by source A
source_b_records
ColumnTypeDescription
source_row_idPKINTUnique row identifier in source B
record_idINTBusiness record identifier
amountNUMERIC(12,2)Amount reported by source B
statusVARCHAR(30)Record status reported by source B
Tablessource_a_recordssource_b_records
Interviewer

Your question is Discrepancy Query Between Sources. 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.