Reputation: 525
ID Name
i need a query returns group order by count like;
ID Name
Upvotes: 1
Views: 1874
Reputation: 610
Check This
SELECT id, Name FROM user
GROUP BY Name
ORDER BY COUNT(Name) DESC;
Upvotes: 0
Reputation: 1551
Try this it might be helpful,
SELECT COUNT(Name) AS total, id, Name
FROM table_name
GROUP BY Name
ORDER BY COUNT(Name) DESC;
Upvotes: 2
Reputation: 263693
SELECT @rownum:=@rownum+1 AS ID,
NameList.iName
FROM
(SELECT DISTINCT iName, COUNT(iName) AS iCount
FROM people
GROUP BY iName
ORDER BY iCount DESC) NameList,
(SELECT @rownum:=0) r
change this subquery
(SELECT DISTINCT iName, COUNT(iName) AS iCount
FROM people
GROUP BY iName
ORDER BY iCount DESC)
to the table with the list of name.
Upvotes: 1