I was asked by a friend of mine how to select the last 3 people that have logged in to the website and I'm quite embarassed but it seems I just can't do it even if my life depended on it. DDL:DECLARE @myTable table (VisitorID int, Login datetime)insert into @myTable (VisitorID, Login)SELECT 1, '2004-03-01 01:01:01' UNION ALL SELECT 2, '2004-03-02 01:01:01' UNION ALLSELECT 3, '2004-03-03 01:01:01' UNION ALL SELECT 1, '2004-03-04 01:01:01' UNION ALLSELECT 4, '2004-03-01 01:01:01' UNION ALL SELECT 5, '2004-03-02 01:01:01' UNION ALLSELECT 4, '2004-03-03 01:01:01' UNION ALL SELECT 5, '2004-03-04 01:01:01' UNION ALLSELECT 1, '2004-03-05 01:01:01' UNION ALL SELECT 2, '2004-03-05 01:01:01'
EDIT: THis is what I have come up with so far but naturally it fails:SELECT DISTINCT TOP 3 VisitorID FROM @myTable ORDER BY Login DESC--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand"