The data table records the bibliography used for user verification. Now I want to retrieve all the bibliography and use DISTINCT and group by to get the expected results, but I found that the returned results are arranged differently, distinct is displayed in the order of data storage, while group by is sorted (generally ASC ). DISTINCT is actually very similar to the implementation of the group by operation, except that only one record is retrieved in each GROUP after group. Therefore, the implementation of DISTINCT is similar to that of group by, and there is no big difference. It can also be achieved through loose index scanning or compact index scanning. Which of the following is more efficient for DISTINCT and group? The DISTINCT operation only needs to find all the different values. The group by operation also requires preparation for other Aggregate functions. At this point, the group by operation should do more work than DISTINCT. But in fact, group by is more efficient. Why? For the DISTINCT operation, it reads all records, and the number of records to be read by group by is as large as the number of groups in the GROUP, that is, it is much less than the actual number of records.
Author lcffufly