sql group by versus distinct

后端 未结 5 1864
予麋鹿
予麋鹿 2020-12-01 10:30

Why would someone use a group by versus distinct when there are no aggregations done in the query?

Also, does someone know the group by versus distinct performance c

5条回答
  •  鱼传尺愫
    2020-12-01 11:03

    In MySQL I've found using a GROUP BY is often better in performance than DISTINCT.

    Doing an "EXPLAIN SELECT DISTINCT" shows "Using where; Using temporary " MySQL will create a temporary table.

    vs a "EXPLAIN SELECT a,b, c from T1, T2 where T2.A=T1.A GROUP BY a" just shows "Using where"

提交回复
热议问题