Last updated on August 4th, 2024 at 11:04 pm
This Leetcode problem Customers Who Never Order LeetCode Solution is done in SQL.
List of all LeetCode Solution
Level of Question
Easy
Customers Who Never Order LeetCode Solution
Table of Contents
Problem Statement
Column Name | Type |
id | int |
name | varchar |
Customers
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.
Column Name | Type |
id | int |
customerId | int |
Orders
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.
Write a solution to find all customers who never order anything.
Return the result table in any order.
The result format is in the following example.
Example 1:
Input:
id | name |
1 | Joe |
2 | Henry |
3 | Sam |
4 | Max |
id | customerId |
1 | 3 |
2 | 1 |
Output:
Customers |
Henry |
Max |
Customers Who Never Order LeetCode Solution MySQL
select Name as Customers from Customers where Id not in ( select CustomerId from Orders );