Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL JOIN With Missing Values
00:00
5 left

SQL JOIN With Missing Values

MediumSQL · PostgreSQL

Problem

Write a SQL query involving a JOIN and handling missing values using IFNULL.

Asked in the Virtual Onsite stage. SQL question involving join operations and missing data handling.

Task

Use the tables below to return each order with its customer name and a fallback region when the customer region is missing.

Requirements

  1. Join orders to customers on customer_id.
  2. Return order_id, order_date, customer_name, and region.
  3. If customers.region is NULL, show 'Unknown' instead.
  4. Keep orders even when the customer record is missing, and show 'Unknown Customer' for the name.

Output

Schema

orders
ColumnTypeDescription
order_idPKINTOrder identifier
customer_idINTReferences customers.customer_id
order_dateDATEDate the order was placed
customers
ColumnTypeDescription
customer_idPKINTCustomer identifier
customer_nameVARCHAR(100)Customer name
regionVARCHAR(50)Customer region, may be missing
Tablesorderscustomers
Interviewer

Your question is SQL JOIN With Missing Values. 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.