Back to course home
0% completed
DISTINCT Clause
DISTINCT
In MySQL, the DISTINCT
keyword is used in the SELECT
statement to eliminate duplicate rows from the result set. It is commonly used when you want to retrieve unique values from a specific column or a combination of columns in a table.
Syntax
The syntax for the DISTINCT
clause is as follows:
SELECT DISTINCT column1, column2 FROM table_name WHERE condition;
Example
Suppose we have a Products
table as shown below:
and we want to retrieve the distinct categories:
SELECT DISTINCT category FROM Products;
MYSQL
MYSQL
. . . .
The result of this query would be a table showing the following rows:
Mark as Completed
Table of Contents
DISTINCT
Syntax
Example