DISTINCT
Last updated
Last updated
When querying data from a table, you may get duplicate rows. In order to remove these duplicate rows, you use the DISTINCT
clause in the SELECT
statement.
Here is the syntax of the DISTINCT
clause:
DISTINCT
examplesLet’s take a look at a simple example of using the DISTINCT
clause to select the unique last names of employees from the employees
table.
First, query the last names of employees from the employees
table using the following SELECT
statement:
As clearly shown in the output, some employees have the same last name e.g, Bondur,Firrelli
.
This statement uses the DISTINCT
clause to select unique last names from the employees
table:
As you can see from the output, duplicate last names has been eliminated in the result set.