How to use distinct and count in SQL query?

Discussion RoomCategory: Database&SQLHow to use distinct and count in SQL query?
Nick asked 5 years ago

count(): It returns the number of rows in a table satisfying the condition specified in the WHERE clause. It would return 0 if there were no matching conditions.

SELECT COUNT(*) FROM category WHERE ‘status’ = 1;
distinct(): It is used to return only different values. In a table, a column often contains many duplicate values, and sometimes we want to list the different values. It can be used with aggregates functions.

SELECT DISTINCT class FROM College ORDER BY department

Scroll to Top