Sunday, March 12, 2017


In a database table, there may exist duplicate data items in terms of ids, name, values, etc. At times, database users might need to retrieve only unique records from a table. Users can retrieve the unique data from the database table using the DISTINCT statement. It is used to access and retrieve the distinct data values from a table in the database.

The SQL DISTINCT command is used with SELECT statement for retrieving only distinct or unique data from the database.

To select distinct values from all the columns (*) asterisk is used, and to select distinct values from some column(s) then those column(s) name must be specified in the SQL SELECT DISTINCT statement.

Syntax of DISTINCT:
      SELECT DISTINCT select_column_list

DISTINCT specifies that only the unique rows should appear in the result set.

select_column_list is the list of columns for which the data is to be listed.

FROM specifies the location from where the data is retrieved. Either from a table or from a view.

Features of DISTINCT:

·         It returns only distinct or unique values.
·         It removes all the duplicate entries from the result-set.
·         Can also be used with aggregates: COUNT, AVG, MIN, MAX, etc.
·         Can work on multiple columns.
Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.