Table of Contents
The SQL SELECT DISTINCT Statement
The SELECT DISTINCT statement is used to return only distinct (different) values.
In our table (data), we might have many times repeated values (duplicate values) but we want to get only unique (different) values.
SELECT DISTINCT Syntax
SELECT DISTINCT column1, column2, ... FROM table_name;
Below is the example of a database table named “details”.
Example: Use the ‘SELECT’ statement to return all records from column ‘section_id’.
SELECT section_id FROM details;
Now, let’s use ‘SELECT DISTINCT’ to return the different records.
SELECT DISTINCT Examples
Example: Use the ‘SELECT DISTINCT’ statement to return the different records from column ‘section_id’.
SELECT DISTINCT section_id FROM details;
The following SQL statement lists the number of different (distinct) section_id from the table details
Example: Use the ‘COUNT’ statement to return the number of different records in column section_id.
SELECT COUNT (DISTINCT section_id) FROM details;
If you find anything incorrect in the above-discussed topic and have further questions, please comment below.