DISTINCT Clause


 

 

SQLite: DISTINCT Clause

This SQLite tutorial explains how to use the SQLite DISTINCT clause with syntax and examples.

 

Description:

The SQLite DISTINCT clause is used to remove duplicates from the result set. The DISTINCT clause can only be used with SELECT statements.

 

Syntax:

 

Parameters or Arguments:

expressions

The columns or calculations that you wish to retrieve.

tables

The tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause.

conditions

The conditions that must be met for the records to be selected.

Note: When only one expression is provided in the DISTINCT clause, the query will return the unique values for that expression. When more than one expression is provided in the DISTINCT clause, the query will retrieve unique combinations for the expressions listed.

 

Examples:

  • The following SQLite statement selects only the distinct values from the “Position” columns from the “Employee” table:

    position
    developer
    manager
    Team Lead
    designer
    research analyst
  • The following SQLite statement selects only the distinct values from the combinations of “Position” columns and “hire_date” from the “Employee” table:

    position hire_date
    developer 1/1/2014
    manager 1/1/2012
    Team Lead 1/1/2013
    developer 6/1/2013
    designer 1/1/2013
    research analyst 1/1/2013
    research analyst 1/1/2014
    6/1/2013