WITH latestPrice AS( SELECt ProductID, StartDate, Price, ROW_NUMBER() OVER (PArtition BY ProductID ORDER BY StartDate DESC) rn FROM TableName), initalPrice AS( SELECt ProductID, StartDate, Price, ROW_NUMBER() OVER (PArtition BY ProductID ORDER BY StartDate ASC) rn FROM TableName )SELECt a.ProductID, b.StartDate, b.Price InitalPrice, c.StartDate LatestDate, c.Price LatestPriceFROM (SELECt DISTINCT ProductID FROM tableName) a INNER JOIN initalPrice b ON a.ProductID = b.ProductID AND b.rn = 1 INNER JOIN latestprice c ON a.ProductID = c.ProductID AND c.rn = 1