Answer the question
In order to leave comments, you need to log in
What is the difference between the following approaches in sampling?
Good mood to you all!
In these two approaches, the result is the same, but the first one spends 30ms on the sample, and the second 30s. What is the fundamental difference?
Option 1
SELECT [FormId], count(F.Id)
FROM [Application].[FormFieldsDataContent] F with(nolock) join
(select Id from [Schema].ProjectForms with(nolock) where Period_id in (902,855)) A on F.FormId=A.Id
where PeriodId in (902,855)
group by [FormId]
SELECT [FormId], count(F.Id)
FROM [Application].[FormFieldsDataContent] F with(nolock) join
[Schema].ProjectForms A with(nolock) on F.FormId=A.Id and F.PeriodId=A.Period_id
where A.Period_id in (902,855)
group by [FormId]
Answer the question
In order to leave comments, you need to log in
In the second, you need to transfer the Period_id in (902,855)) condition to the join phrase, like this:
SELECT [FormId], count(F.Id)
FROM [Application].[FormFieldsDataContent] F with(nolock) join
[Schema].ProjectForms A with(nolock) on A.Period_id in (902,855) and F.FormId=A.Id and F.PeriodId=A.Period_id
group by [FormId]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question