Some Java Guy
Some Java Guy

Reputation: 5118

Distinct and Count in table

Need to write a MySQL query to check the database table and fetch distinct values and its count.

enter image description here

select distinct(fruits), count(distinct(fruits)) from table;

Will this suffice?

Upvotes: 0

Views: 67

Answers (1)

bonCodigo
bonCodigo

Reputation: 14361

Why not use a group by

select fruits, count(fruits) as fc
from table
group by fruits
order by fc desc;

Upvotes: 3

Related Questions