我有以下查詢有點慢,因爲你可以看到where子句中有幾個嵌套查詢,任何人都可以想出更好的解決方案嗎?如何最小化多個子查詢?
SELECT m.briefmedialist,
Count(DISTINCT s.value) AS selected,
m.briefmedialistid
FROM vwmedialistmediachannels m
LEFT JOIN sessionfilters s
ON s.field = 'Media'
AND m.briefmedialistid = s.value
AND s.sessionid = @SessionID
WHERE m.id = (SELECT d.briefid
FROM dashboards d
WHERE d.dashboardguid IN (SELECT value
FROM sessionfilters s
WHERE s.sessionid = @SessionID
AND s.field = 'DashboardID'))
GROUP BY m.briefmedialist,
m.briefmedialistid
ORDER BY m.briefmedialist
您可以添加一個索引,使查詢執行得更快 – 2013-07-18 12:10:16
你能告訴我們查詢中涉及的表的結構,他們擁有的索引以及該查詢試圖產生的是什麼? –
你是否確定***子查詢是性能問題的來源? –