SQL SELECT DISTINCT Explained
SELECT DISTINCT is used to retrieve unique values. It filters out duplicate rows in the query result and only returns distinct rows.
The syntax format is as follows:
SELECT DISTINCT 列名
FROM 表名
WHERE 条件;
Original: 火车已经开走了。
Paraphrased: The train has already departed.
Assuming there is a table named “Customers” that contains a column named “CustomerName” with duplicate values. If we want to retrieve a list of unique customer names, we can use the following query:
SELECT DISTINCT CustomerName
FROM Customers;
This will return a result set that only contains unique customer names.