Obtaining the most reoccurring attribute in SQL -


using sql, have table list of usernames , trying output repeated 1 out using max. new sql appreciated!

thanks

you can use aggregate function count() total number of times username repeated:

select username, count(username) total yourtable group username order total desc 

then depending on database can return username appears most.

in mysql, can use limit:

select username, count(username) total yourtable group username order total desc limit 1; 

see sql fiddle demo

in sql server, can use top:

select top 1 ties username, count(username) total yourtable group username order total desc 

see sql fiddle demo


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -