How to use the DISTINCT statement in SQL?
In SQL, the DISTINCT keyword is used to return unique, non-repeating records. It can be applied to columns or fields in a SELECT statement to eliminate duplicate values.
The syntax for using the DISTINCT keyword is as follows:
SELECT DISTINCT 列名 FROM 表名;
The column name is the name of the column where unique values must be selected, while the table name is the name of the table to be selected.
Here is an example using the DISTINCT keyword:
Suppose we have a table named “customers” with a column for “country,” and we want to select a list of unique countries.
SELECT DISTINCT country FROM customers;
This query will return a list of unique countries.