Sub queries or OUTER joins
which one has better performance?
SELECT *,(SELECT MAX(开发者_开发问答old) FROM employee WHERE employee.CompanyId = Company.Id)
FROM Company
or
SELECT *,MAX(old) FROM Company LEFT OUTER JOIN employee
ON Company.Id = employee.CompanyId
?
how about bigger queries ?
thank you
Run both queries in SQL Server Management Studio and look at the execution plan.
The execution plan will not only tell you which part of the query took how much resources, but also which of the two queries took more resources than the other (if you run the both together, the execution plan shows values in percent).
If you know how to read execution plans then have a look at that. A guess is that SQL Server will optimize both queries to the same execution plan anyway.
Subquery has generally lower performance than JOIN queries.
精彩评论