Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 A better way?

Author  Topic 

bloushi
Starting Member

1 Post

Posted - 2009-04-12 : 01:55:04
Hello Everybody...

I would like some help with this query. I want to avoid three index scans on this relatively huge table. Any better ways to do it?

SELECT aa.AssessmentId,aa.QuestionId, aa.PointsObtained,o.OrganizationId, o.CountryId
FROM (
SELECT AssessmentId, QuestionId, PointsObtained, ROW_NUMBER() OVER(PARTITION BY QuestionId ORDER BY PointsObtained DESC, AssessmentId Desc) as RowNumber
FROM AssessmentAnswers
) as aa
JOIN Assessments AS a ON aa.AssessmentId = a.AssessmentId
JOIN Organizations AS o ON a.OrganizationId = o.OrganizationId
WHERE aa.RowNumber = 1
ORDER BY QuestionId


I would appreciate any suggestions. Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-12 : 13:23:53
which table is index scans happening? which columns are indexes on?
Go to Top of Page
   

- Advertisement -