Distinct: Used to filter duplicate records. It is often used only to return the number of non-repeating records, rather than using it to return all values that are not re-recorded. The reason is that distinct only with double-loop query to solve, and so for a very large number of stations, will undoubtedly directly affect the efficiency.
Form Name table
Id |
NAME |
1 |
A |
2 |
B |
3 |
B |
4 |
C |
1. Example: Query the name for all data that is not duplicated. Note: Distinct must be placed at the beginning
Select distinct from Table
2. Query the name for all data that is not duplicated, including the ID.
Select distinct from Table
So it's important to note that there are multiple fields behind the distinct, which are multi-conditional, and are duplicates only when these conditions are the same.
3. Want to get the following results how to write SQL
Select * from Table Group by name
Summarize:
Distinct is used to go heavy.
Must be placed in the first after the select
Multiple fields behind distinct are multi-conditional deduplication, which is the only way to duplicate records if these conditions are the same.
Usage of SQL Server database distinct