This SQLite post explains how to use the SQLite DISTINCT clause with syntax and examples.
The SQLite DISTINCT clause is used to remove duplicates from the result set. The DISTINCT clause can only be used with SELECT statements.
The syntax for the DISTINCT clause in SQLite is:
The columns or calculations that you wish to retrieve.
The tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause.
Optional. The conditions that must be met for the records to be selected.
Let's look at the simplest example of how to use the DISTINCT clause in SQLite. We can use the DISTINCT clause to remove duplicates from our result set, which is comprised of just a single field.
For example:
This SQLite DISTINCT example would return all unique last_name values from the employees table.
Let's look at how you might use the SQLite DISTINCT clause to remove duplicates from more than one field in your SELECT statement.
For example:
This SQLite DISTINCT clause example would return each unique last_name and first_name combination from the employees table. In this case, the DISTINCT applies to each field listed after the DISTINCT keyword, and therefore returns distinct combinations.