Forum Moderators: open
Suppose I have in a table :
id : msg_id 1 : 1 2 : 2 3 : 1 4 : 1 5 : 3 6 : 2 7 : 3 8 : 3 9 : 1 10 : 1
A query that will give me the msg_ids in decreasing order of their number of occurrences. For above example, it should give : 1, 3 and 2
SELECT DISTINCT (msg_id), COUNT( msg_id ) AS msgcount FROM discussions GROUP BY msg_id ORDER BY msgcount DESC
SELECT msg_id, COUNT(msg_id) AS msgcount FROM discussions GROUP BY msg_id ORDER BY msgcount DESC
Haven't tried it but this should also work.