How to make this SQL query using IN (with many numeric IDs) more efficient?

Viewed 166

I've been waiting over an hour already for this query, so I know I'm probably doing something wrong. Is there efficient way to tailor this query: ?

select RespondentID, MIN(SessionID) as 'SID'
from BIG_Sessions (nolock)
where RespondentID in (
1418283,
1419863,
1421188,
1422101,
1431384,
1435526,
1437284,
1441394,
/* etc etc THOUSANDS */
1579244 )
    and EntryDate between
    '07-11-2011' and '07-31-2012'
GROUP BY RespondentID 

I kknow that my date range is pretty big, but I can't change that part (the dates are spread all over) .

Also, the reason for MIN(SessionID) is because otherwise we get many SessionID's for each Respondent, and one suffices(it's taking MIN on an alphanumeric ID like ach2a23a-adhsdx123... and getting the first alphabetically)

Thanks

2 Answers
Related