The DISTINCT keyword is used to remove duplicate rows from MySQL query results, leaving only unique values. Its usage includes: DISTINCT column_name: Remove duplicate values from the specified column. DISTINCT(column_name1, column_name2, ...): Remove duplicate values from a combination of multiple columns.
Usage of DISTINCT in MySQL
Question: What is the role of DISTINCT in MySQL?
Answer:
The DISTINCT keyword is used to remove duplicate rows from query results, retaining only unique values.
Detailed description:
DISTINCT has the following usage:
Note:
Example:
SELECT DISTINCT name FROM customers;
This query will select all unique names from the "customers" table.
SELECT DISTINCT city, country FROM customers;
This query will select unique city and country combinations from the "customers" table.
The above is the detailed content of Usage of DISTINCT in mysql. For more information, please follow other related articles on the PHP Chinese website!