SQL SELECT DISTINCT Statement

Tiempo de lectura: < 1 minuto

Reading Time: < 1 minutes

Good afternoon everyone,

Today, we continue with SQL tutorials, and we will explain the SQL SELECT DISTINCT statement with examples.

SQL SELECT DISTINCT is a clause used in SQL to select only the unique values from a column or set of columns in a table. It is very useful when we want to obtain a clean list of values without duplicates.

The syntax to use SELECT DISTINCT is as follows:

SELECT DISTINCT column1, column2, ...
FROM table_name;

For example, if we want to obtain the unique values from the “name” column of the “customers” table, we could write the following query:

SELECT DISTINCT name
FROM customers;

It is also possible to use SELECT DISTINCT with multiple columns, as in the following example where we get the unique values from the “name” and “city” columns of the “customers” table:

SELECT DISTINCT name, city
FROM customers;

I hope you like it and as always, I hope it helps you.

:books:

Leave a Comment