一个美女程序员朋友今天换Blog了,开篇第一文(http://whitecloud.cnblogs.com/archive/2006/07/13/449879.aspx)就是惊人之作,不过我认为此文颇有“不调查研究就发言”之嫌。

原文列举的两条做同样事情的SQL语句,并用了“大幅度提高”这一词,但这只不过是想象而已,以为第二条语句会比第一条语句来得快,那就太低估现代数据库对SQL语句的优化能力了,其实,这两条SQL语句在MSSQL里会被优化为以同样的方式来执行,以NorthWind数据库为例,两条SQL语句执行方式和结果完全一样。
从SQL语句的易读性而言,显然,第一条要优于第二条。
select o.* from Orders o
join Customers c on o.CustomerID=c.CustomerID
where c.CustomerID='ANTON'
select o.* from Orders o
,(select CustomerID from Customers where CustomerID='ANTON') c
where o.CustomerID=c.CustomerID