SQL SELECT DISTINCT Statement TUTORIAL

SQL SELECT DISTINCT

The DISTINCT keyword returns only unique values. In a table, a column may contain many duplicate values; and sometimes you only want to list the different values.

SQL SELECT DISTINCT SYNTAX

The DISTINCT keyword is added to the SELECT statement's column listing, directly after the SELECT keyword.

    SELECT DISTINCT column_name,column_name
FROM table_name;

SQL SELECT DISTINCT EXAMPLE

We can see that in our table "books" we have the authors "eli" and "edu" duplicated;

If we wanted only to list the different values, we could write the following query;

SELECT DISTINCT AUTHOR FROM eli.books;

With this result;

<< Previous Next >>