Loading…

How to use distinct and count in SQL query? Explain

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.

Syntax:
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.

Syntax:
SELECT DISTINCT class FROM College ORDER BY department

 

This information was frequently asked during SQL interview questions for testers.

Suggest An Answer

No suggestions avaliable!

Latest post from SQL Interview Questions

Ask Question