У меня есть таблица с определенными данными, относящимися к выполненному пользователем тесту.я хотел получить максимальное (testnumber) из приведенной ниже таблицы вместе со статусом, соответствующим максимальному (testnumber).

SELECT @LastAttemptedTest=MAX([TestNumber] FROM [dbo].[StudentChapterwiseTest] WHERE
[ChapterId]=584 AND [StudentId]=212045
SELECT Status FROM [dbo].[StudentChapterwiseTest] WHERE [TestNumber]=@LastAttemptedTest AND
[ChapterId]=584 AND [StudentId]=212045
я пытаюсь получить этоmax (номер теста) и статус соответствуют результату max (номер теста) в одном запросе на выборку