Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL JOIN With Missing Values

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL JOIN With Missing Values. Start with the requirements and the two tables on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results