有些时候,一个子查询可以被重写为JOIN,例如:
SELECT OrderID FROM Orders where EmployeeID IN
(select EmployeeID from Employees where EmployeeID > 3);
如果知道OrderID是唯一的,即主键或者唯一索引,那么SQL语句会被重写为Join形式。
SELECT OrderID FROM Orders join Employees
where Orders.EmployeeID = Employees.EmployeeID and Employees.EmployeeID > 3;