LeetCode 183:Customers Who Never Order
【Description】
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.
Table: Customers.
Table: Orders.
Using the above tables as example, return the following:
【Solution】
Personal solution:
select name as customers
from customers as c
left join orders as o
on c.id =o.customerid
where o.id is null
Reference solution:
select customers.name as 'Customers'
from customers
where customers.id not in
(
select customerid from orders
);