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
SQL Anti-Join Without Nested Queries
00:00
5 left

SQL Anti-Join Without Nested Queries

MediumSQL · PostgreSQL

Problem

Write a query to list the rows present in a first table but not in a second table without using any nested query.

Use reference_code to determine whether a row in first_table exists in second_table. Rows with a null reference code should be treated as having no match.

Output

  1. Return one row per unmatched row from first_table.
  2. Include row_id, reference_code, and row_description.
  3. Sort by row_id in ascending order.

Schema

first_table
ColumnTypeDescription
row_idPKINTUnique identifier for a row in the first table
reference_codeVARCHAR(20)Code used to find a corresponding row in the second table
row_descriptionVARCHAR(100)Description associated with the first-table row
second_table
ColumnTypeDescription
row_idPKINTUnique identifier for a row in the second table
reference_codeVARCHAR(20)Code that may correspond to a first-table row
row_descriptionVARCHAR(100)Description associated with the second-table row
Tablesfirst_tablesecond_table
Interviewer

Your question is SQL Anti-Join Without Nested 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.