Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.