SELECT DISTINCT u.UserID, UserLastName, UserFirstName, UserName, Notified,
MAX (CycleNumber) as CycleNumber, (CycleCurrentStep) as CycleCurrentStep,
MAX (CycleDateReported) as CycleDateReported,
max (cycleid)
FROM [User] u
left join Cycle c on (u.UserID = c.UserID)
join UserDivSection us on (u.UserID = us.UserID
and us.DivSectionID=26)
group by u.UserID, UserLastName, UserFirstName, UserName, Notified, c.CycleCurrentStep
UserID UserLastName UserFirstName UserName Notified CycleNumber CycleCurrentStep CycleDateReported
290 Williams Craig [email protected] 1 7 0 208
290 Williams Craig [email protected] 1 9 3 210
290 Williams Craig [email protected] 1 7 5 1/29/2010 3:06:23 PM 204
290 Williams Craig [email protected] 1 8 6 2/1/2010 9:26:40 AM 209
We're trying to return rows with unique non-repeating userids matching with the max cyclenumber for that userid. Right now the query is returning the same userid multiple times for various cyclenumbers. We're not exactly sure how to proceed with the correct query. Any help would be appreciated.