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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Join Behavior with Sample Tables
00:00
5 left

Join Behavior with Sample Tables

MediumSQL · PostgreSQL

Problem

Table A has ids (1,1,1,NULL,2,2,NULL,3,3,7,9) and Table B has ids (1,1,2,2,2,3,3,6,8). Give the output of: SELECT a.id with INNER JOIN on a.id=b.id; with LEFT JOIN; with RIGHT JOIN; and SELECT a.id, b.id with RIGHT JOIN.

Asked in the Round 1 live SQL stage. The interviewer pushed, "Are you sure this is correct?" on the RIGHT JOIN NULL handling.

Output

  1. Show each requested result set with its rows and duplicate multiplicity preserved.
  2. Preserve NULL values and distinguish the final RIGHT JOIN output containing both identifiers.
  3. Within each displayed result set, order by a_id ascending with NULLs first, then b_id ascending with NULLs first.

Output details

  • Return columns in this order: result_set, a_id, b_id.
  • Label result sets exactly INNER JOIN, a.id, LEFT JOIN, a.id, RIGHT JOIN, a.id, and RIGHT JOIN, a.id and b.id.
  • Order result sets by result_set ascending before applying the specified a_id and b_id ordering.
  • Treat NULL ids as nonmatching for equality comparisons.

Schema

table_a
ColumnTypeDescription
idINTIdentifier value, including duplicate and NULL values
table_b
ColumnTypeDescription
idINTIdentifier value, including duplicate and unmatched values
Tablestable_atable_b
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.