try something like this:SELECT t.[id], t.groupid, t.lastmodified FROM topic t INNER JOIN(SELECT groupid as max_groupid, max(lastmodified) as max_last FROM topic GROUP BY groupid) t2ON t.groupid = t2.max_groupid AND t.lastmodified = t2.max_lastid groupid lastmodified ----------- ----------- ------------------------------------------------------ 5 2 2005-08-03 20:50:00.0002 1 2005-08-03 06:00:00.000(2 row(s) affected)
-ec