Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Inner Join vs Outer Join
00:00
5 left

Inner Join vs Outer Join

MediumSQL · PostgreSQL

Problem

How do you explain the difference between an inner join and an outer join in a database context?

Write a PostgreSQL query that demonstrates the distinction by returning matched and unmatched records from the provided customer and order data.

Output

  1. One row for each matched relationship and each unmatched record.
  2. Columns: customer_id, customer_name, order_customer_id, order_id, and match_status.
  3. Sort by the related customer identifier, placing unmatched records with null identifiers last, then by order_id.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer associated with the order
order_statusVARCHAR(30)Current order status
Tablescustomersorders
Interviewer

Your question is Inner Join vs Outer Join. 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.