The SQL Select Distinct Statement is also used to select the data from the database the difference here is it will return only distinct (different) values.
Inside a database table, a column may contain duplicate values, and some time you want to list down the different (distinct) values. Example: The scenario could be like from which countries we have customers added in the table.
SELECT DISTINCT column_1, column_2, column_3 FROM table_name
Consider a table having multiple customers from the same country.
SELECT * FROM customers
And if you want to search from which countries do we have customers. so without distinct selection, it will return duplicates entries. So using distinct you can get the proper list.
distinct
SELECT DISTINCT country FROM customers
There could be any scenario where you want the query to return a count. So using DISTINCT and COUNT we can count the countries in which we have customers. Count:
DISTINCT
COUNT
SELECT COUNT(DISTINCT country) FROM customers;
Query in MS Access Here is the workaround for MS Access:
SELECT COUNT(*) AS DistinctCountries FROM (SELECT DISTINCT country FROM customers);