This way
DECLARE @tbl TABLE(Id INT, Marks INT)
INSERT INTO @tbl
SELECT 1,34
UNION ALL
SELECT 2,54
UNION ALL
SELECT 1,23
UNION ALL
SELECT 2,98
UNION ALL
SELECT 1,63
UNION ALL
SELECT 2,59
SELECT TOP 1 Id FROM @tbl WHERE Id = 1
UNION ALL
SELECT Marks FROM @tbl WHERE Id = 1
UNION ALL
SELECT TOP 1 Id FROM @tbl WHERE Id = 2
UNION ALL
SELECT Marks FROM @tbl WHERE Id = 2
Please note data sorting cannot be applied here