这是道题目:
一开始直接下了个这样的查询语句:
select customers.name as 'Customers'
from customers
where customers.id not in
(
select customerid from orders
);
最后运行时间:600ms,这样写的确查询了两个表的确事慢。
介绍几种更快的写法:
用left join on语法
select customers.name as Customers from customers left join orders on customers.id=orders.customerid where orders.id is null
差了三倍效率还是很夸张地。