Skip to Content
TheCornerLabs Docs

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:

1705252620684490 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 here

Exercise Script:

-- Exercise script would be rendered here

Available actions: Execute

The result of this query would be a table showing the following rows:

1736221671496330 Image scaled to 45%

Last updated on