Skip to main content
added [query-performance] to 2412 questions - Shog9 (Id=1924)
Link
Tweeted twitter.com/#!/StackDBAs/status/235162095962972161
Source Link
TheTechGuy
  • 783
  • 3
  • 10
  • 18

which one is more efficient query?

I have a table called STUDENT

+-----------+-----------+-----------+---------------+ | StudentID | FirstName | LastName | EnrollmenDate | +-----------+-----------+-----------+---------------+ | 1 | x | x | x | | 2 | x | x | x | | 3 | x | x | x | +-----------+-----------+-----------+---------------+ 

Write a query that pulls the student who registered the last?

a) select top 1 * from STUDENTorder by EnrollmentDate Desc

or

b) select * from STUDENT where EnrollmentDate = (select Max(EnrollmentDate) from STUDENT)

I tend to ask this question in interview. One candidate answered b) I was expecting a). Which one is better query?