【SQL】183. Customers Who Never Order

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.

+----+-------+
| Id | Name  |
+----+-------+
| 1  | Joe   |
| 2  | Henry |
| 3  | Sam   |
| 4  | Max   |
+----+-------+

Table: Orders.

+----+------------+
| Id | CustomerId |
+----+------------+
| 1  | 3          |
| 2  | 1          |
+----+------------+
1 # Write your MySQL query statement below
2 select Name Customers
3 from Customers
4 where Id not in (select CustomerId
5                  from Orders);

 

posted @ 2017-03-03 12:21  wilderness  阅读(188)  评论(0编辑  收藏  举报