Andy Brownsword breaks out the stopwatch:
The
TOP
clause limits the number of results which are returned from a query, in this instance we’re focussing on a single result. In contrast, when usingMAX
we’re applying a function to our data to select the largest value from our data.Let’s dive into some examples with the StackOverflow data, specifically the Votes table.
Read on for several scenarios and how the two perform. Things get a bit more complicated as you introduce other tables in joins and similar additional factors, but this gives you a good foundation for comparison.