mysql distinct group by 哪个好

如题所述

distinct只是将重复的行从结果中出去;
group by是按指定的列分组,一般这时在select中会用到聚合函数。
distinct是把不同的记录显示出来。
group by是在查询时先把纪录按照类别分出来再查询。
group by 必须在查询结果中包含一个聚集函数,而distinct不用。
加了索引 distinct 比没加索引的 distinct 快了 107倍。

加了索引 group by 比没加索引的 group by 快了 43倍。
加不加索引 group by 都比 distinct 快。
建议选 group by
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答