A site contains two tables, Customers table and the Orders table. Write a SQL query to find all customers never ordered anything.
Customers 表:
+----+-------+
| Id | Name |
+----+-------+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
+----+-------+
Orders 表:
+ ---- + ------------ +
| Id | CustomerId |
+ ---- + ------------ +
| 1 | 3 |
| 2 | 1 |
+ ---- + ------------ +
example given in the table above, your query should return:
+-----------+
| Customers |
+-----------+
| Henry |
| Max |
+-----------+
Ideas: Isolated appeared CustomerId, which name corresponds id if not in this list, you qualify.
select Name as 'Customers'
from Customers
where Id not in(
select CustomerId from Orders
);