Performance effect of using TOP 1 in a SELECT query

前端 未结 4 846
挽巷
挽巷 2021-02-12 10:28

I have a User table where there are a Username and Application columns. Username may repeat but combination of Username + Application is unique, but I don\'t have the unique con

4条回答
  •  梦毁少年i
    2021-02-12 11:09

    If there's more than one row in the results and no ORDER BY clause, the "TOP 1" saves a ton of work for the server. If there's an order by clause the server still has to materialize the entire result set anyway, and if there's only one row it doesn't really change anything.

提交回复
热议问题