2
是否有可能採取以下SQL提高性能:CROSS APPLY性能
SELECT t1.id,
t1.name,
t2.subname,
t2.refvalue
FROM table1 AS t1
CROSS apply (SELECT TOP 1 t2.subid,
t2.subname,
t3.refvalue
FROM table2 AS t2
INNER JOIN table3 AS t3
ON t2.subid = t3.subid
ORDER BY lastupdated DESC) AS t2
所以它看起來像這樣重寫它:
SELECT t1.id,
t1.name,
t2.subname,
t3.refvalue
FROM table1 AS t1
CROSS apply (SELECT TOP 1 t2.subid,
t2.subname
FROM table2 AS t2
ORDER BY lastupdated DESC) AS t2
INNER JOIN table3 AS t3
ON t2.subid = t3.subid
是的我得到了同樣的結果。你們看到的東西表明這些做不了同樣的事情嗎?如果它有任何幫助subId只映射到table3中的一個記錄。重寫查詢的目的是爲了提高性能。這是我正在重寫的更復雜的查詢的簡化版本。一旦我擁有它,我會讓你知道統計/查詢計劃的內容。 –