SQLite SELECT DISTINCT
is a useful way to make sure your data is clean and free of duplicates. It’s also a good way to find unique values in a column or combination of columns. SQLite select distinct can be used to remove duplicate records from a table.
Syntax
SELECT DISTINCT * FROM table_name;
This would return the entire table with all duplicates removed.
Example
SELECT DISTINCT city FROM customers;
This would return a list of all the unique cities in the customers table.
You can also use SQLite select distinct on multiple columns. This can be useful if you want to make sure there are no duplicate rows in your table.
SELECT DISTINCT column_1, column_2 FROM table_name;
This would return all the unique combinations of column_1 and column_2 from the table.
SQLite select distinct can also be used with the count()
function to return the number of unique values in a column or combination of columns.
SELECT DISTINCT count(column_name) FROM table_name;
This would return the number of unique values in the column.