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:
Image scaled to 70%
and we want to retrieve the distinct categories:
SELECT DISTINCT category
FROM Products;Database Exercise
Database Schema:
-- Database schema would be rendered hereExercise Script:
-- Exercise script would be rendered hereAvailable actions: Execute
The result of this query would be a table showing the following rows:
Image scaled to 45%
Last updated on