Distinct Query to get unique records of the table from SQLite database with WHERE & ORDER BY

preview_player
Показать описание
List of all Python SQLite tutorials

By using DISTINCT query we can get unique data of a column. Let us find out how many class are there in the records.
SELECT DISTINCT(class) from student
We can display in the order of classes by using order by query
SELECT DISTINCT(class) FROM student ORDER BY class
We can get the number of unique class in our student table. Here is the SQL
SELECT COUNT(DISTINCT(class)) FROM student
We can use two columns
SELECT DISTINCT class, sex FROM student
We can handle null data as distinct value, if you don’t want to include null data then use NOT NULL in query
SELECT DISTINCT class FROM student WHERE class NOT NULL
Рекомендации по теме
join shbcf.ru