An aggregate may not appear in the WHERE clause I'm attempting to execute the following query to return a data set where the Updated Date is the most recent. I'm thinking my joins are causing the issue, but I'm not sure, and have not made any progress.

   SELECT wd.SAPID, rd.RequestID, vd.VersionTableID,rd.ProjectReference,contactinfo.FirstName,contactinfo.LastName,
                 wd.ActualEndDate, wd.IsIndependentContractor,we.AssignmentStartDate, vd.VersionNo, we.CreatedDate, we.UpdatedDate
   FROM RequestDetails rd
   INNER JOIN  WorkerDetails wd ON  rd.RequestTableID = wd.RequestTableID
   INNER JOIN WorkerExtension we ON we.WorkerID=wd.WorkerID
   INNER JOIN dbo.Address_Info addressinfo ON addressinfo.WorkerID = wd.WorkerID
   INNER JOIN dbo.Contact_Info contactinfo ON contactinfo.WorkerID = we.WorkerID
   INNER JOIN VersionDetails vd ON   vd.RequestTableID = rd.RequestTableID
   WHERE we.AssignmentEndDate &gt;= '2/16/2016' AND EndDate &lt;= '2/20/2016' AND contactinfo.FirstName = 'Barsegyan' AND we.UpdatedDate = (SELECT MAX(we.UpdatedDate))
   GROUP BY wd.SAPID, rd.RequestID, vd.VersionTableID,rd.ProjectReference,contactinfo.FirstName,contactinfo.LastName,
                 wd.ActualEndDate, wd.IsIndependentContractor,we.AssignmentStartDate, EndDate, vd.VersionNo, we.CreatedDate, we.UpdatedDate


A sample of the data I'm querying:


And the error:
AND we.UpdatedDate = (SELECT MAX(we.UpdatedDate)) is the offending statement.

Two easy ways to solve this are to get the Max(we.UpdateDate) in a variable first, or add an inner join (select max(we.UpdateDate) from WorkerExtension ) and joing that back to the "we" aliased table.