0
+-----------------------+------------------------+
| being_followed        | follower               |
+-----------------------+------------------------+
| Bob Dylan             |                      B |
| Bob Dylan             |                      A |
| Sam Cooke             |                      X |
| The Beatles           |                      Y |
| Bob Dylan             |                      M |
| Sam Cooke             |                      N |
+-----------------------+------------------------+

Now, I want to find which is the most occurring value in being_followed and then order by it. It should look somewhat like -

Bob Dylan - 3
Sam Cooke - 2
The Beatles - 1

Please don't mark this as a duplicate.

6 Answers6

1

Try below :

select being_followed , count(1) as count
from table
group by being_followed 
order by count desc ;
minatverma
  • 1,090
  • 13
  • 24
0

Try This:-

select being_followed,count(*) total_followers
from table
group by being_followed
order by total_followers desc
jitendra joshi
  • 677
  • 5
  • 18
0
SELECT being_followed , count(being_followed )as counter FROM `table_Name` GROUP BY being_followed ORDER BY counter DESC

You will get result what you want.Here using group by you will get unique value and using count you will get counter of same being_followed

jilesh
  • 436
  • 1
  • 3
  • 13
0

Try this:

SELECT being_followed,COUNT(*) AS follower 
FROM tablename GROUP BY being_followed ORDER BY follower DESC;

Output:

+-----------------------+------------------------+
| being_followed        | follower               |
+-----------------------+------------------------+
| Bob Dylan             |                      3 |
| Sam Cooke             |                      2 |
| The Beatles           |                      1 |
+-----------------------+------------------------+
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
0

Try this

SELECT being_followed,COUNT(1) count_followers
FROM table
GROUP BY being_followed
ORDER BY COUNT(1) DESC;

Get count of being_followed and also order by high to low bases(descending order)

Vipin Jain
  • 3,686
  • 16
  • 35
0

Perhaps you can try this:

select being_followed, count(*) follower
from TableName
group by being_followed
order by follower desc

It's working fine.

Suvro
  • 352
  • 2
  • 13