/*
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
*/
SET STATISTICS IO ON
SET STATISTICS TIME ON
SELECT TOP 10 *
FROM UserTraces AS ut1
WHERE ActionID<>2
AND NOT EXISTS(
SELECT 1
FROM UserTraces
WHERE ExtensionID1=ut1.ExtensionID1 AND ActionID<>2 AND CreateDate>ut1.CreateDate
)
ORDER BY CreateDate DESC
SELECT TOP 10 *
FROM UserTraces AS t1
Where EXISTS
(
SELECT *
FROM UserTraces AS t2
WHERE ActionID<>2
GROUP BY ExtensionID1
HAVING ExtensionID1 = t1.ExtensionID1
and max(CreateDate) = t1.CreateDate
)
ORDER BY CreateDate DESC
SET STATISTICS TIME OFF
SET STATISTICS IO OFF