Which is better: Distinct or Group By

后端 未结 6 989
南方客
南方客 2021-02-07 12:45

Which is more efficient?

SELECT  theField
FROM    theTable
GROUP BY theField

or

SELECT  DISTINCT theField
FROM    theTable
         


        
6条回答
  •  我在风中等你
    2021-02-07 13:09

    In MySQL, DISTINCT seems a bit faster than GROUP BY if theField is not indexed. DISTINCT only eliminate duplicate rows but GROUP BY seems to sort them in addition.

提交回复
热议问题