Selecting unique records in a MySQL query: select distinct

Using the distinct construct is relevant not only for selecting unique entries. This is a good way to test the application. The main semantic load on the select distinct MySQL query keyword is to select only those records in which the specified field has a unique value.

select distinct




You can use multiple fields in a single query. You can combine fields with MySQL functions, apply additional conditions in the selection and sorting. Using the group by construct is also acceptable, but the uncertainties that arise from this must be taken into account.

Basic Provisions and Syntax

Testing and optimization: select distinct is one of the most popular ways to achieve what you want. A case in point is a table containing 99,999 records, which are randomly generated from three arrays:

Author's example is not a picture




ex_workers PHP rand (0,10). 11 . , 99 999 first_name last_name .





Author's example is not a picture




, , $aWorkersF, , $aWorkersL. , - . - .

Author's example is not a picture




(1) (2) - - , first_name last_name . 121 - (3) (4).

distinct `first_name`, `last_name` distinct concat (`first_name`, `last_name`). , .





MySQL select c distinct

: . . i_status w_status. , .

select distinct optimization




i_status w_status , ex_workers i_status, . .

select distinct , -. . , .

, - , , select distinct.

- . PHP , , , . , . - .

select distinct mysql




select distinct - , , :

  • ;
  • ;
  • () .

, , select distinct.

- . - , .

select distinct mysql




- , . , select distinct . : , .

- - .




All Articles