Find Customers with No Matching Order

Quick Overview

Return the names of customers who have never placed an order. Match Customers.id to Orders.customerId and label the result Customers. The row order does not matter.

Find Customers with No Matching Order

Company: Meta

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

### Problem Return the names of customers who have never placed an order. Match Customers.id to Orders.customerId and label the result Customers. The row order does not matter. ### Tables Table: `Customers` ```text +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | +-------------+---------+ id is the primary key (column with unique values) for this table. Each row of this table indicates the ID and name of a customer. ``` Table: `Orders` ```text +-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | customerId | int | +-------------+------+ id is the primary key (column with unique values) for this table. customerId is a foreign key (reference columns) of the ID from the Customers table. Each row of this table indicates the ID of an order and the ID of the customer who ordered it. ``` ### Example ```text Customers (id,name): (1,Ada), (2,Bo), (3,Cam) Orders (id,customerId): (8,2), (9,2) Output (Customers): (Ada), (Cam) ``` ### What a Strong Answer Covers - Identify every customer without a matching order. - Preserve one output row per qualifying customer regardless of repeated names or repeated orders. - Return the requested column and handle empty inputs. ### Follow-up Questions - How would the answer change if only orders from a given date range counted? - How would you return the number of customers without orders?

Overview: Return the names of customers who have never placed an order. Match Customers.id to Orders.customerId and label the result Customers. The row order does not matter.

Meta logo
Meta
easySoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Return the names of customers who have never placed an order. Match Customers.id to Orders.customerId and label the result Customers. The row order does not matter.

Tables

Table: Customers

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| id          | int     |
| name        | varchar |
+-------------+---------+
id is the primary key (column with unique values) for this table.
Each row of this table indicates the ID and name of a customer.

Table: Orders

+-------------+------+
| Column Name | Type |
+-------------+------+
| id          | int  |
| customerId  | int  |
+-------------+------+
id is the primary key (column with unique values) for this table.
customerId is a foreign key (reference columns) of the ID from the Customers table.
Each row of this table indicates the ID of an order and the ID of the customer who ordered it.

Example

Customers (id,name): (1,Ada), (2,Bo), (3,Cam)
Orders (id,customerId): (8,2), (9,2)
Output (Customers): (Ada), (Cam)

What a Strong Answer Covers Guidance

  • Identify every customer without a matching order.
  • Preserve one output row per qualifying customer regardless of repeated names or repeated orders.
  • Return the requested column and handle empty inputs.

Follow-up Questions Guidance

  • How would the answer change if only orders from a given date range counted?
  • How would you return the number of customers without orders?