我有超過10個參與此SP。在帶下劃線的行中,有一個表AllData由於where子句中的字段名而被連接了3次。Mulitple加入查詢
有關如何更好地處理此複雜查詢的任何建議將不勝感激。大多數情況下,爲了避免多次加入AllData(別名爲ad1,adl2,adl3)。這可能會影響性能。
這裏是SP
ALTER PROCEDURE [dbo].[StoredProc1]
AS
select case when pd.Show_Photo = '1,1,1'
then i.id
else null
end as thumbimage,
t1.FPId,
'WebProfile' as profiletype,
mmbp.Name as Name,
t1.Age,
t1.Height,
adl.ListValue as AlldataValue1,
adl2.ListValue as AlldataValue2,
adl3.ListValue as AlldataValue3,
c.CName,
ed.ELevel,
ed.EDeg,
NEWID()
from Table2 mmbp, Table3 u
join Table1 t1 on t1.Pid = u.Pid
left join Table4 mmb on t1.Pid= mmb.Pid
join table5 i on t1.Pid = i.Pid
join table6 pd on t1.Pid = pd.Pid
join table7 ed on t1.Pid = ed.Pid
join table8 c on t1.xxx= c.xxx
join AllData adl on t1.xxx = adl.ListKey
join AllData adl2 on b.ms = adl2.ListKey
join AllData adl3 on b.Diet = adl3.ListKey
where adl.FieldName=xxx and
adl2.FieldName='ms' and
adl3.FieldName='Diet' and
------
Table2(別名mmbp)和where語句中省略條件中的任何其他表之間是否存在連接條件?另外,在運行查詢時,是否可以包含查詢的其餘部分以及查詢計劃? – 2012-01-27 10:10:08