Sqlite Distinct Keyword
# SQLite DISTINCT Keyword
SQLite's **DISTINCT** keyword is used with the SELECT statement to eliminate all duplicate records and fetch only unique records.
It is possible for a table to contain multiple duplicate records. When fetching such records, the DISTINCT keyword is particularly useful as it fetches only unique records instead of duplicate ones.
## Syntax
The basic syntax of the DISTINCT keyword to eliminate duplicate records is as follows:
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE
## Example
Consider the COMPANY table with the following records:
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ----------1 Paul 32 California 20000.02 Allen 25 Texas 15000.03 Teddy 23 Norway 20000.04 Mark 25 Rich-Mond 65000.05 David 27 Texas 85000.06 Kim 22 South-Hall 45000.07 James 24 Houston 10000.08 Paul 24 Houston 20000.09 James 44 Norway 5000.010 James 45 Texas 5000.0
First, let us look at the following SELECT query that will return duplicate salary records:
sqlite> SELECT name FROM COMPANY;
This will produce the following result:
NAME ----------PaulAllenTeddyMarkDavidKimJamesPaulJamesJames
Now, let us use the **DISTINCT** keyword in the above SELECT query:
sqlite> SELECT DISTINCT name FROM COMPANY;
This will produce the following result, with no duplicate entries:
NAME ----------PaulAllenTeddyMarkDavidKimJames
YouTip