The basic principle of the distinct statement in MySQL and its comparison with group by, mysqldistinct
DISTINCT is actually very similar to the implementation of the group by operation, except that only one record is retrieved in each GROUP after
This article mainly introduces the index optimization distinct statement and the multi-field operation method of distinct in MySQL. the de-duplication function of distinct statements is the basic knowledge in MySQL beginners, for more information,
MySQL usually completes the distinct operation using groupby (essentially a sort action), and if the distinct operation is combined with the by-order operation, a temporary table is usually used. This can affect performance. In some cases, MySQL can
The bibliography used in the user verification is recorded in the datasheet, and now I want to take out all the bibliographies, using distinct and group by to get the results I want, but I find that the return results are arranged in a different
The value of distinct is displayed only once.
No matter how many times this value appears, it is only displayed once.
Select distinct field name 1, field name 2 from Table order by field name 1
It is best to use it in combination with order.
First,MySQL distinct technical point 1, create table:CREATE TABLE t1 (ID varchar, name varchar);2. Insert Data :INSERT into T1 values (1,a);INSERT into T1 values (2,B);INSERT into T1 values (3,C);INSERT into T1 values (4,C);INSERT into T1 values
Distinct shows only one repeat of the value.
No matter how many times this value appears, it appears only once.
Select DISTINCT field name 1, field name 2 from table order by field name 1
It is best used in conjunction with the order by. can
This article mainly compares the performance of distinct and groupby in MySQL. the content is more detailed and the comparison results can be seen intuitively, if you are interested, you can refer to some tests you have seen on the Internet recently.
Recently saw a number of online tests, the feeling is not very accurate, today personally tested some. It is concluded that the testing process on personal computers may not be comprehensive enough for reference only.
Test process:Prepare a test
First, basic usedistinctis generally used to remove duplicate records in the query results, and this statement in select , insert , delete and update can only be used in, select the specific syntax is as follows:select distinct
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.