If the semantic organization of information would be embodied in reality, then the scope of the MySQL distinct construct would instantly self-destruct. Modern databases are built as part of a relational relationship between data, so the task of removing duplicate records is relevant.
The appearance of identical rows, as a rule, is not a problem that cannot be solved, but to avoid duplication of the contents of the table fields is almost impossible in many cases.
Database organization
It is believed that the “correct” database contains unique tables, and each of them contains unique fields. The presence of the same content in the fields of different tables is allowed only if they are key and a logical connection of data is carried out on them.
For example, the staffing scheme will go to the employee data table for a specific field. The staffing table contains only what applies to it in the context of a particular enterprise, and the list of employees contains only personal data of the personnel.
With this version of the data, MySQL distinct will work on a query to both tables, which connects the staffing with employees.
Uniqueness of tables and fields
In the interaction of the staff table and the list of employees for each row of the first table there is a special place in the second. The second table may contain the same surnames, first names, middle names of people, residential addresses in the city may also contain identical streets. The numbers of houses and apartments may not have much significance (they do not take up much space).
Ideally, all the same words are placed in different tables and they have a unique key. For example, a list of all streets, last names, names, patronymics. In the employee table, the primary schemes merge in the desired version of the presentation, and not a list of employees is connected to the staff table, but a request to it and those associated with it.
The more systematized the information, the more relevant the use of MySQL distinct. For the correct organization of the data you have to "pay" - when combining tables, the total number of rows in the selection increases in proportion to the number of rows in each table. This is an abstract example, usually the developer does not detail the information to such an extent. Using MySQL distinct solves this problem: only the required records will be selected.
The task may be to parse paragraphs into sentences, sentences into phrases, and phrases into words. In this case, you can’t do without a dictionary, and you will have to make dictionaries of conjugations, endings and other elements of the language syntax for it.
MySQL query example "select distinct ..."
There are entries in the table in which there are four seasons and two entry states: active and passive. Sample Examples:
- all entries;
- only unique;
- unique within the conditions.
They may be as indicated in the image in the article.
The functionality of the sampling operator only unique records satisfy any data structures. You can use the query in the query, group and sort the data before selecting.
However, it is always preferable to simplify the work with the database as much as possible. Using MySQL distinct on one field is always preferable to working on several.
It is especially important to carefully compile queries that combine multiple tables. Any combination of data in relational databases before the where and join constructions begin to function results in large amounts of data. Orientation in them requires attention and accuracy from the developer.