I need some help optimizing a query or even suggestions on other solutions. My current query looks at a table of responses to a request table. There can be multiple response to each individual request but what I want is the earliest response to each request that comes from a certain group of users (stored on another table.) Here's what I use right now:



Code:
SELECT A.request_id, A.response_from, A.response_date
FROM dbo_CPO_REQUEST_RESPONSE AS A INNER JOIN (SELECT R.request_id,MIN(R.response_date) AS MinResponse 
FROM dbo_CPO_REQUEST_RESPONSE R  WHERE response_from IN (SELECT username FROM dbo_User WHERE dept_num IN ("24000", "20465", "20470", "45540")) 
OR response_from IN (SELECT UserID FROM tblCPOUsers)
GROUP BY R.request_id)  AS B ON (A.response_date=B.MinResponse) AND (A.request_id=B.request_id);
dbo_CPO_REQUEST_RESPONSE is the response table. dbo_User is a table that contains users currently employed; tblCPOUsers is a table of users who are no longer employed or have left the department but I still want to pull their user name since they were in the department when they originally responded.

This query gives me what I want but it is extremely slow. There are only ~ 33K records on the response table so I wouldn't think a query like this should take > 10 minutes sometimes.