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
Post a Comment