什么是更好的,WITH语句或左连接3表?

时间:2017-04-01 12:53:10

标签: sql-server

Plz告诉我mssql中的2个查询之间哪个更好?

;with ab as (select a.*,b.CategoryName from Products a 
left join Categories b on a.CategoryID = b.CategoryID where b.CategoryID = 2)
select * from ab left join Suppliers c on ab.SupplierID = c.SupplierID

select * from Products a left join Categories b on a.CategoryID = b.CategoryID
left join Suppliers c on a.SupplierID = c.SupplierID
where b.CategoryID = 2

1 个答案:

答案 0 :(得分:1)

是相同的,WITH只有帮助使代码更具可读性。

您可以使用EXPLAIN QUERY How do I obtain a Query Execution Plan?

对其进行测试