Customers Without Orders
MediumSQLDatabaseSorting
Description
Write a SQL query to return the names of customers who have never placed an order, ordered by name ascending. **Output columns (in order):** name
Table:
customers| Column | Type |
|---|---|
| id | INT |
| name | TEXT |
Table:
orders| Column | Type |
|---|---|
| id | INT |
| customerId | INT |
Examples
Input:
CREATE TABLE customers (id INT, name TEXT); CREATE TABLE orders (id INT, customerId INT); INSERT INTO customers VALUES (1,'Ann'),(2,'Ben'),(3,'Cal'); INSERT INTO orders VALUES (1,1),(2,1);Output:
Ben
CalExplanation:
Customers are matched to their orders and only those with no matching order are kept, by name.
Input:
CREATE TABLE customers (id INT, name TEXT); CREATE TABLE orders (id INT, customerId INT); INSERT INTO customers VALUES (1,'A'),(2,'B');Output:
A
BExplanation:
Customers are matched to their orders and only those with no matching order are kept, by name.
Input:
CREATE TABLE customers (id INT, name TEXT); CREATE TABLE orders (id INT, customerId INT); INSERT INTO customers VALUES (1,'Zoe'),(2,'Amy'),(3,'Bob'); INSERT INTO orders VALUES (1,2);Output:
Bob
ZoeExplanation:
Customers are matched to their orders and only those with no matching order are kept, by name.
Constraints
- •
Use standard SQL (SQLite).