SQL performance MAX()

前端 未结 4 2034
遇见更好的自我
遇见更好的自我 2020-12-11 02:13

Just got a small question. When trying to get a single max-Value of a table. Which one is better?

SELECT MAX(id) FROM myTable WHERE (whatever)
4条回答
  •  执念已碎
    2020-12-11 02:30

    The first one is certainly clearer in the intention.

    There shouldn't be a significant performance difference thought for this specific query (they should actually be pretty much identical, even though the result is different if there are no rows in myTable). Unless you have a valid reason to tune the query (e.g. a proven performance issue), always pick the one which shows the intent of the code.

提交回复
热议问题