6. Find Customers Without Orders
Beginner Mode
Objective
Construct an SQL query to identify and list the names of all customers who have never placed an order. Ensure the resulting list is ordered alphabetically by the customers' names.
Additional information
You are provided with two tables:
The customers table:
| Column | Type | Description |
|---|---|---|
| customer_id | integer | Unique identifier for each customer |
| customer_name | string | Name of the customer |
The orders table:
| Column | Type | Description |
|---|---|---|
| order_id | integer | Unique identifier for each order |
| customer_id | integer | Identifier linking the order to a customer |
| order_date | date | The date on which the order was placed |
Your query should return a table with a single column, customer_name, containing the names of customers who have no corresponding entries in the orders table. If every customer has placed at least one order, the query should return an empty result set.
Examples
Example 1:
Output:
Input:
| customers | |
|---|---|
| customer_id | customer_name |
| 1 | Alice Smith |
| 2 | Bob Johnson |
| 3 | Carol White |
| 4 | David Brown |
| orders | ||
|---|---|---|
| customer_id | order_date | order_id |
| 1 | 2023-01-01 | 1 |
| 1 | 2023-01-15 | 2 |
| 3 | 2023-02-01 | 3 |
| customer_name |
|---|
| Bob Johnson |
| David Brown |
Code Environment
Sign in or try as guest to run your code.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
LinkedIn
Revolut
Accenture
Adobe
Google
Samsung
Datadog
Wix
Dropbox
Meta
OpenAI
Hulu
Uber
X
DoorDash
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Bloomberg
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla