MAX vs Top 1 - which is better?

前端 未结 7 1782
慢半拍i
慢半拍i 2020-12-03 02:35

I had to review some code, and came across something that someone did, and can\'t think of a reason why my way is better and it probably isn\'t, so, which is better/safer/mo

相关标签:
7条回答
  • 2020-12-03 03:21

    Performance is generally similar, if your table is indexed.

    Worth considering though: Top usually only makes sense if you're ordering your results (otherwise, top of what?)

    Ordering a result requires more processing.

    Min doesn't always require ordering. (Just depends, but often you don't need order by or group by, etc.)

    In your two examples, I'd expect speed / x-plan to be very similar. You can always turn to your stats to make sure, but I doubt the difference would be significant.

    0 讨论(0)
提交回复
热议问题