Zohaib Baig
Zohaib Baig

Reputation: 21

getting most repeated value fromo sql table fields

I want to get most one repeated value in sql table column field below is my sql structure.

I want to get most repeated value from Topic field

Table name is Orange and field name with values is topic

topic
 1
 2
 1
 3
 1
 2

Upvotes: 0

Views: 1318

Answers (4)

Fluffeh
Fluffeh

Reputation: 33542

select topic, count(topic) from orange group by topic order by count(topic) desc;

That is the SQL query to run btw.

Upvotes: 0

ZuRom
ZuRom

Reputation: 91

SELECT    count(topic) 
FROM      Orange  
GROUP BY  topic
ORDER BY  count(topic) DESC

Upvotes: 2

bkwint
bkwint

Reputation: 626

SELECT MAX(COUNT(`topic`)) FROM `Orange`;

Upvotes: 0

Luke Baughan
Luke Baughan

Reputation: 4686

What you're looking for here is the Modal average - check this link that has an example of Modal operations in Sql Server and adapt as required.

http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/calculating-mean-median-and-mode-with-sq

Upvotes: 0

Related Questions