In the table, duplicate values may be included. That's not a problem, but sometimes you might want to just list different values (distinct). Keyword DISTINCT is used to return only different values.
Table A:
Example 1
Select distinct name from A
The following results are performed:
Example 2
Select DISTINCT name, ID from A
The following results are performed:
is actually based on "Name+id".
Example 3: Statistics
Select COUNT (distinct name) from A; --The number of the table name to go back to, SQL Server support, and Access does not support select COUNT (distinct name, id) from A; --sql server and access do not support
Example 4
Select ID, distinct name from A; --The error will be indicated because the distinct must be placed at the beginning
Other
The field selected in the distinct statement can only be a field specified by distinct, and other fields are not possible. For example, if Table A has a memo column, if you want to get Distinc name and the corresponding Memo field, it is not possible to go directly through distinct.
However, there are other ways to implement a discussion of how SQL Server will stitch up multiple lines of content into one row
Distinct Data deduplication Keywords