DISTINCT Clause in SQLite

SQLite DISTINCT Clause To fetch only the unique records from a table the SQLite DISTINCT clause is used with the SELECT statement.

Syntax:

SELECT DISTINCT column_1, column_2,.....column_N   
FROM table_name  
WHERE conditions;

Example: TEACHERS Table:

ID NAME SALARY SUBJECT
1 Jim 10000 Geology
2 John 20000 Geology
3 Watson 15000 Physics
4 Holmes 25000 Chemistry
5 Tony 30000 Physics

SELECT DISTINCT SUBJECT 

FROM TEACHERS;

Output:

SUBJECT
Geology
Physics
Chemistry

Explanation: In the above example, all the duplicate records from the table are eliminated and only the unique records are fetched from the SUBJECT column of the TEACHERS table.

Please follow and like us:
Content Protection by DMCA.com