题目描述:
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.
Using the above tables as example, return the following:
方法一:利用嵌套子查询和not in
SELECT customers.name AS 'customers'
FROM customers
WHERE customers.Id NOT in(
SELECT customersId FROM orders)
方法二:利用left join
select customers.name AS 'customers'
from customers left join orders on customers.id=orders.customersId
where orders.id is null;