If you are looking to get other fields other than the accountname and the min and max dates, you can do something like shown below:;WITH cte as( SELECT *, ROW_NUMBER() OVER (PARTITION BY username, accountname ORDER BY theDateColumn ASC) AS Oldest, ROW_NUMBER() OVER (PARTITION BY username, accountname ORDER BY theDateColumn DESC) AS Newest FROM YourTable)SELECT a.*, b.*FROM cte a INNER JOIN cte b ON a.username = b.username AND a.accountname = b.accountnameWHERE a.Oldest = 1 AND b.Newest = 1;