Grokking SQL for Tech Interviews
Ask Author
Back to course home

0% completed

DISTINCT Clause
Table of Contents

DISTINCT

Syntax

Example

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

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:

Image
Mark as Completed

Table of Contents

DISTINCT

Syntax

Example