Skip to the content.
< PREVIOUS   NEXT >

SELECT DISTINCT

The SELECT DISTINCT statement is used to return only distinct (different) values. To elimnate duplicate element while selecting any column.

Distinct means Different.

SELECT DISCTINCT SYNTAX

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

Above statement will give differenet values of Column1, Column2 and so on.

EXAMPLE

Suppose there is a Table name as “CustomerComplaint” having CustomerID, CustomerName, ProductName Issue, City, PostalCode and Country as columns.


If we have to select different values of City from CustomerComplaint.

SELECT DISTINCT City FROM CustomerComplaint;


If we have to count the different City from CustomerComplaint

SELECT COUNT(DISTINCT City) FROM CustomerComplaint;


The example above will not work in Firefox Because COUNT(DISTINCT column_name) is not supported in Microsoft Access databases. Firefox is using Microsoft Access in our examples.

For MS Access:

SELECT Count(*) AS DistinctCountries
FROM (SELECT DISTINCT Country FROM Customers);
< PREVIOUS   NEXT >

HOME