1.

How to use distinct and count in SQL query? Explain

Answer»

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.



Discussion

No Comment Found