logo

SQL SELECT DISTINCT

⇒ The SELECT DISTINCT statement is used to return only distinct (different) values. Simply put, it is used to return only unique values.

⇒ The DISTINCT clause is used to remove duplicates from the result set of a SELECT statement. Within a table, a column often contains many duplicate values, and sometimes you only want to list the different (distinct) values.

SQL SELECT DISTINCT SQL Example Table

SELECT without DISTINCT

SELECT without DISTINCT

SELECT with DISTINCT

SQL SELECT with DISTINCT

To count Distinct values

To count Distinct values in SQL

Notes:

⇒ When only one column (expression) is provided in the DISTINCT clause, the query will return the unique values for that column.

⇒ When more than one column (expression) is provided in the DISTINCT clause, the query will retrieve unique combinations for the columns listed.

⇒ In SQL, the DISTINCT clause doesn't ignore NULL values. So when using the DISTINCT clause in your SQL statement, your result set will include NULL as a distinct value.

By correcting spelling mistakes, grammar mistakes, and conceptual errors, this version provides a clear and accurate explanation of the SELECT DISTINCT statement and its usage.

Next ❯ ❮ Previous
discription of faastop website
logo