题解 | #查询结果去重#
查询结果去重
https://www.nowcoder.com/practice/82ebd89f12cf48efba0fecb392e193dd
select distinct university from user_profile; select university from user_profile group by university; 在语义相同,有索引的情况下:group by和distinct都能使用索引,效率相同。 在语义相同,无索引的情况下:distinct效率高于group by。原因是distinct 和 group by都会进行分组操作,但group by可能会进行排序,触发filesort,导致sql执行效率低下。