I think you're missing a where clause.
Select Top 1 SubjectID, CourseID, EnrolDate, Absence, Remark from Course Where StudentID = 38
Because you filter by StudentID 38 you don't need to order by it. After that, the Query should be fine since StudentID is part of the primary key, so SQL Server should use index seek to look for the enry.
Is the query well optimized
![](https://techprofile.blob.core.windows.net/images/JJSkWQSoxk6JIfr1n1FAog.png?8DA15F)
BenTam-3003
686
Reputation points
Dear All,
According to the design of the index, is the following query well optimized?
sSql = "Select Top 1 SubjectID, CourseID, EnrolDate, Absence, Remark from Course Order by StudentID = 38
Accepted answer
-
Christopher Geckert 91 Reputation points
2022-08-15T05:27:52.5+00:00
1 additional answer
Sort by: Most helpful
-
BenTam-3003 686 Reputation points
2022-08-15T08:07:53.963+00:00 Hi Christopher,
Thanks for your reply.